webpack-encore: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
Hello, I tried to upgrade webpack-encore on a Symfony 5.3 project
I followed the doc well, and upgraded webpack-encore and stimulus. I also modified the controllers.json as shown.
But when I try the npm run dev command, I have the following error:
[webpack-cli] Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration.module.rules[3].type should be one of these:
"javascript/auto" | "javascript/dynamic" | "javascript/esm" | "json" | "webassembly/experimental"
-> Module type to use for the module
- configuration.output has an unknown property 'assetModuleFilename'. These properties are valid:
object { auxiliaryComment?, chunkCallbackName?, chunkFilename?, chunkLoadTimeout?, crossOriginLoading?, devtoolFallbackModuleFilenameTemplate?, devtoolLineToLine?, devtoolModuleFilenameTemplate?, devtoolNamespace?, filename?, futureEmitAssets?, globalObject?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateFunction?, hotUpdateMainFilename?, jsonpFunction?, jsonpScriptType?, library?, libraryExport?, libraryTarget?, path?, pathinfo?, publicPath?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine?, webassemblyModuleFilename? }
-> Options affecting the output of the compilation. `output` options tell webpack how to write the compiled files to disk.

I tried modifying my webpack.config.js leaving only the bare minimum to see if it came from that. But the problem persists so I don’t understand where it came from
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 11
- Comments: 26 (6 by maintainers)
This solved my problem:
Sorry to say, but IMHO this isn’t solved yet.
lib/config-generator.js line 252 defines the property “assetModuleFilename” which is stated as “invalid config object”.
Hi! I’m running into this exact same issue.
Error
Webpack Config
Package.json
When I install Webpack(“webpack”: “^5.24.2”) as a dev dependency the build is successful. After this install, I get the following error:
Webpack is already provided by Webpack Encore, also adding it to your package.json file may cause issues.On the other hand, thing to note, when I run npm install --force, I had this warning:
It happened on the new project that I had just created.
And I got the same error on my own project when I finally ran “npm update” Should we care?
Apart from
sass-loaderbothdevDependenciesshould’ve matched the same versions when doing a fresh install or anpm update.My guess is that when you updated
@symfony/webpack-encorenpm didn’t updatewebpack(that comes with it) for some reason.It seems that you are using an old version of Webpack, could you also show the content of your
package.jsonfile?Here is how I fixed the problem.
Run
npm list webpack. I got something like this:my_project@ /home/me_user/Projects/my_project_files ├─┬ @symfony/webpack-encore@1.6.1 │ ├─┬ @nuxt/friendly-errors-webpack-plugin@2.5.1 │ │ └── webpack@4.46.0 deduped │ ├─┬ assets-webpack-plugin@7.0.0 │ │ └── webpack@5.52.1 deduped │ ├─┬ babel-loader@8.2.2 │ │ └── webpack@4.46.0 deduped │ ├─┬ clean-webpack-plugin@3.0.0 │ │ └── webpack@4.46.0 deduped │ ├─┬ css-loader@5.2.7 │ │ └── webpack@4.46.0 deduped │ ├─┬ css-minimizer-webpack-plugin@2.0.0 │ │ └── webpack@5.52.1 deduped │ ├─┬ mini-css-extract-plugin@1.6.2 │ │ └── webpack@4.46.0 deduped │ ├─┬ style-loader@2.0.0 │ │ └── webpack@4.46.0 deduped │ ├─┬ terser-webpack-plugin@5.2.4 │ │ └── webpack@5.52.1 deduped │ ├─┬ webpack-cli@4.8.0 │ │ ├─┬ @webpack-cli/configtest@1.0.4 │ │ │ └── webpack@4.46.0 deduped │ │ └── webpack@4.46.0 deduped │ ├─┬ webpack-dev-server@4.2.0 │ │ ├─┬ webpack-dev-middleware@5.1.0 │ │ │ └── webpack@4.46.0 deduped │ │ └── webpack@4.46.0 deduped │ └── webpack@5.52.1 ├─┬ dotenv-flow-webpack@1.1.0 │ └─┬ webpack@4.46.0 │ └─┬ terser-webpack-plugin@1.4.5 │ └── webpack@4.46.0 deduped ├─┬ sass-loader@10.2.0 │ └── webpack@4.46.0 deduped └─┬ workbox-webpack-plugin@6.3.0 └── webpack@4.46.0 deduped
Two different versions of webpack are listed. npm couldn’t resolve the conflict and used both (?). To resolve the conflict, use this list and uninstall all of the packages that depend on webpack. From above, for me, these included @symfony/webpack-encore@1.6.1; dotenv-flow-webpack@1.1.0; sass-loader@10.2.0; and workbox-webpack-plugin@6.3.0. For you, it will be different, but probably the encore will have the most dependencies. Whatever you do, MAKE SURE YOU KEEP A LIST OF THESE PACKAGES!!!
After doing this, make sure you no longer have webpack installed anywhere by running the
npm list webpackagain.my_project@ /home/me_user/Projects/my_project_files └── (empty)
Then install webpack with
npm install webpack. This should give you the latest version. Check itnpm list webpack.my_project@ /home/me_user/Projects/my_project_files └─┬ webpack@5.52.1 └─┬ terser-webpack-plugin@5.2.4 └── webpack@5.52.1 deduped
Then reinstall all the packages you removed. All of the packages accepted the latest version of webpack except one: dotenv-flow-webpack@1.1.0. For that I ran
npm install dotenv-flow-webpack --force. This gave me errors, but it still installed and everything still worked fine. Instead of using force, you might be able to find an alternative package that allows webpack version 5+.my_project@ /home/me_user/Projects/my_project_files ├─┬ @symfony/webpack-encore@1.6.1 │ ├─┬ @nuxt/friendly-errors-webpack-plugin@2.5.1 │ │ └── webpack@5.52.1 deduped │ ├─┬ assets-webpack-plugin@7.0.0 │ │ └── webpack@5.52.1 deduped │ ├─┬ babel-loader@8.2.2 │ │ └── webpack@5.52.1 deduped │ ├─┬ clean-webpack-plugin@3.0.0 │ │ └── webpack@5.52.1 deduped │ ├─┬ css-loader@5.2.7 │ │ └── webpack@5.52.1 deduped │ ├─┬ css-minimizer-webpack-plugin@2.0.0 │ │ └── webpack@5.52.1 deduped │ ├─┬ mini-css-extract-plugin@1.6.2 │ │ └── webpack@5.52.1 deduped │ ├─┬ style-loader@2.0.0 │ │ └── webpack@5.52.1 deduped │ ├─┬ terser-webpack-plugin@5.2.4 │ │ └── webpack@5.52.1 deduped │ ├─┬ webpack-cli@4.8.0 │ │ ├─┬ @webpack-cli/configtest@1.0.4 │ │ │ └── webpack@5.52.1 deduped │ │ └── webpack@5.52.1 deduped │ ├─┬ webpack-dev-server@4.2.0 │ │ ├─┬ webpack-dev-middleware@5.1.0 │ │ │ └── webpack@5.52.1 deduped │ │ └── webpack@5.52.1 deduped │ └── webpack@5.52.1 deduped ├─┬ dotenv-flow-webpack@1.1.0 │ └── webpack@5.52.1 deduped invalid ├─┬ sass-loader@10.2.0 │ └── webpack@5.52.1 deduped ├── webpack@5.52.1 └─┬ workbox-webpack-plugin@6.3.0 └── webpack@5.52.1 deduped
npm ERR! code ELSPROBLEMS npm ERR! invalid: webpack@5.52.1 /home/me_user/Projects/my_project_files/node_modules/webpack
npm ERR! A complete log of this run can be found in: npm ERR! /home/trent/.npm/_logs/2021-09-10T15_57_57_679Z-debug.log
Again, those errors came from forcing dotenv-flow-webpack to use version 5 of webpack. However, it still worked fine (so far…).
UPDATE: In my case, a version of webpack is built in with @symfony/webpack-encore. If you install webpack separately it will conflict with the version that is installed with @symfony/webpack-encore. In this case, simply install @symfony/webpack-encore FIRST before installing all the other packages that require webpack. When you do this, npm will use @symfony/webpack-encore’s version of webpack for the other packages. AGAIN, use the force command as indicated above for any packages that may require an older version of webpack. It might work. If it doesn’t, then try to find a substitute that will work with the later version of webpack.
That’s it I just solved the problem, I don’t really know by what miracle.
In fact I created a new project, and installed the dependencies.
Then I saw in the package.json that these versions were needed:
There are some that did not match my own project’s package.json :
So I just replaced the devDependencies with those from the new project.
Then I ran npm install then npm update, and everything works!
But was the problem really there?