Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

@svgr/webpack fails with 'Plugin name should be specified'

ErrorError: Plugin name should be specified

Short answer

The error comes from SVGO, which SVGR runs on every SVG. An entry in svgoConfig.plugins is an object without a name field. Write each plugin as a plain string, or as an object with name and params. If you do not need optimisation, set svgo to false.

  • Applies to webpack 5, @svgr/webpack 8, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find the svgoConfig in your webpack rule or in svgr.config.js and read each plugin entry.

    grep -rn "svgoConfig" -A8 webpack.config.js svgr.config.js
  2. 2Match what you see, then jump to its fix

    1. 1The config has entries like { removeViewBox: false } inside pluginsA plugin entry is an object without a nameFix
    2. 2The config error persists or you only need the componentYou do not need SVG optimisationFix

What does the error look like?

  • Error: Plugin name should be specified

Cause 1 of 2

A plugin entry is an object without a name

1Check

SVGO accepts a plugin as a string with its ID, or as an object with a name and optional params. Every object form in its documentation has name.

grep -rn "plugins" -A6 webpack.config.js

2Fix

Rewrite each entry in one of those two forms. To switch a default plugin off, override it inside preset-default.

// webpack.config.js
{
  loader: '@svgr/webpack',
  options: {
    svgoConfig: {
      plugins: [
        {
          name: 'preset-default',
          params: { overrides: { removeViewBox: false } },
        },
        'removeDoctype',
      ],
    },
  },
}

3Verify

Rebuild and import an svg file.

npx webpack

Confirmed by svgo.dev

Did this fix it?

Cause 2 of 2

You do not need SVG optimisation

1Check

SVGO runs by default (svgo: true) and svgoConfig defaults to null.

grep -rn "svgo" webpack.config.js svgr.config.js

2Fix

Turn SVGO off for this loader.

{ loader: '@svgr/webpack', options: { svgo: false } }

3Verify

Rebuild and check that the SVG still renders.

npx webpack

Confirmed by react-svgr.com

Did this fix it?

How do I stop it coming back?

  • Copy plugin config from the SVGO documentation of the version you have installed.
  • Keep SVGR options in one svgr.config.js instead of repeating them in each rule.
  • Check svgo options after upgrading @svgr/webpack.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.