webpack 5 cjs config with esm module

Viewed 32

I have initialized a new webpack 5 app, the default config file webpack.config.js contains CJS code.

If I add "type": "module" to package.json I get [webpack-cli] ReferenceError: require is not defined in ES module scope, you can use import instead.

I read that this shouldn't happen. Changing extension of the webpack config file to .cjs solves the problem but I do not like to have a .cjs extension in the project. Is this really the expected behavior?

0 Answers
Related