TL;DR
Rename webpack.config.js
to webpack.config.cjs
The problem is that webpack doesn't support ES6 config file. This means that when you set the type
of a package to module
webpack.config.js
interpreted as an ES6 module, which is not supported yet.
Solutions/workarounds:
Set the type
of a package to module
and rename webpack.config.js
to webpack.config.cjs
which results that entire your project will interpreted as ES6 modules, except the webpack.config.cjs
which remains a commonjs
file.
Keep the type
of a package commonjs
and rename all of your files to mjs
(except webpack.config.js
)
Use a different bundler, eg, rollup.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…