Maaz Zindani

Loading the index…

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

webpack says the configuration object does not match the API schema

ErrorInvalid 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.

  • Applies to webpack 5, webpack-cli 6, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 30
  2. 2Match what you see, then jump to its fix

    1. 1configuration.module.rules[0] has an unknown property 'loaders' (or 'query')Rule.loaders or Rule.query from webpack 4Fix
    2. 2configuration has an unknown property or a wrong value under 'node'node.* polyfill options such as node.fs: 'empty'Fix
    3. 3The path starts with configuration.optimization or configuration.outputRenamed or removed optimization and library optionsFix

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.js

2Fix

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 webpack

Confirmed by webpack.js.org

Did this fix it?

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.js

2Fix

Remove node.Buffer and node.process entries. Replace node.fs set to empty with a resolve fallback.

resolve: {
  fallback: { fs: false },
},

3Verify

Rebuild.

npx webpack

Confirmed by webpack.js.org

Did this fix it?

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.js

2Fix

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 webpack

Confirmed by webpack.js.org

Did this fix it?

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

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.