webpack 은 .mjs 를 javascript/esm 으로 고정해 CommonJS 를 막는다1 — type 을 직접 주면 그 기본 규칙을 건너뛴다2.
configureWebpack: {
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
],
},
},
Footnotes
-
Module Methods | webpack: “
.mjsor.jswith"type": "module"inpackage.json” → “No CommonJS allowed, for example, you can’t userequire,module.exportsorexports”. webpack 4 기본 규칙:{ test: /\.mjs$/i, type: "javascript/esm" }↩ -
Module | webpack: “
Rule.typesets the type for a matching module. This prevents defaultRules and their default importing behaviors from occurring.” ↩