webpack says the configuration object does not match the API schema
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.Short answer
Webpack checks your config against a schema before it builds. The message lists each unknown or wrong property with a path such as configuration.module.rules. Most often the config was written for webpack 4 and uses options that webpack 5 removed or renamed. Read the property path, then replace that option.
Fix it fast
1Find out which cause you have
Read the property path in the message, for example configuration.node or configuration.module.rules[0]. It names the exact place in your config to change.
npx webpack --config webpack.config.js 2>&1 | head -n 302Match what you see, then jump to its fix
- 1
configuration.module.rules[0] has an unknown property 'loaders' (or 'query')Rule.loaders or Rule.query from webpack 4Fix - 2
configuration has an unknown property or a wrong value under 'node'node.* polyfill options such as node.fs: 'empty'Fix - 3
The path starts with configuration.optimization or configuration.outputRenamed or removed optimization and library optionsFix
- 1
What does the error look like?
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
Cause 1 of 3
Rule.loaders or Rule.query from webpack 4
1Check
Search your rules for the old keys.
grep -n "loaders\|query" webpack.config.js2Fix
Webpack 5 replaced Rule.loaders with Rule.use, and Rule.query with options.
module: {
rules: [
{
test: /\.js$/,
use: [{ loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } }],
},
],
},3Verify
Run the build again; that property should no longer be listed.
npx webpackConfirmed by webpack.js.org
Cause 2 of 3
node.* polyfill options such as node.fs: 'empty'
1Check
Look for a node block in the config.
grep -n -A6 "node:" webpack.config.js2Fix
Remove node.Buffer and node.process entries. Replace node.fs set to empty with a resolve fallback.
resolve: {
fallback: { fs: false },
},3Verify
Rebuild.
npx webpackConfirmed by webpack.js.org
Cause 3 of 3
Renamed or removed optimization and library options
1Check
Compare your options with the migration table. For example noEmitOnErrors, namedModules and hashedModuleIds are gone.
grep -n "noEmitOnErrors\|namedModules\|namedChunks\|hashedModuleIds\|libraryTarget" webpack.config.js2Fix
Use the new names: emitOnErrors, moduleIds and chunkIds, and output.library as an object.
optimization: { emitOnErrors: true, moduleIds: 'named' },
output: { library: { name: 'MyLibrary', type: 'commonjs2' } },3Verify
Rebuild.
npx webpackConfirmed by webpack.js.org
How do I stop it coming back?
- After upgrading webpack, run the build once before touching anything else, and clear the schema errors one by one.
- Keep the config small; delete options that equal the defaults.
- Pin webpack, webpack-cli and plugins together in package.json.
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
webpack-dev-server says the options object does not match the API schema
Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
Webpack-dev-server validates devServer options when it starts.
4 causes, each with a fixWeb 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 fix