@svgr/webpack fails with 'Plugin name should be specified'
Error: Plugin name should be specifiedShort 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.
Fix it fast
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.js2Match what you see, then jump to its fix
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.js2Fix
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 webpackConfirmed by svgo.dev
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.js2Fix
Turn SVGO off for this loader.
{ loader: '@svgr/webpack', options: { svgo: false } }3Verify
Rebuild and check that the SVG still renders.
npx webpackConfirmed by react-svgr.com
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix