webpack Failed to load 'webpack.config.js' config
Getting this error while doing my local build
[webpack-cli] Failed to load 'webpack.config.js' config
[webpack-cli] ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
And the reason is that i configure my package.json to type: module - which webpack doesn't like.
To resolve this (careful as you might end up breaking your code), i remove it as i intended to use webpack to do hardwork of bundling application for me.
Having type = module in package.json mean you can use import to reference external libraries as oppose to using required (Commonjs).
https://nodejs.org/docs/latest-v21.x/api/esm.html#esm_enabling
Apparently webpack don't like it.
Comments