reactjssvgwebpack

'Error: Plugin name should be specified' @svgr/webpack svgoConfig


I have @svgr/webpack@6.0.0 installed and webpack config as below

use: [
    {
        loader: '@svgr/webpack',
        options: {
            svgoConfig: {
                plugins: [
                    {
                        removeViewBox: false,
                    },
                ],
            },
        },
    },
],

But I am getting an error as below:

Error: Plugin name should be specified

Solution

  • The latest SVGO documentation suggests that you need to assign each plugin object a name. Your configuration is out of date so it's most likely a version/update issue. Try changing the options object in your config to:

    svgoConfig: {
      plugins: [
        {
          name: 'preset-default',
          params: {
            overrides: {
              // disable plugins
              removeViewBox: false,
            },
          },
        },
      ],
    },
    

    The preset-default plugin allows you to customise the defaults and allows you to disable plugins that are enabled by default.