webpack 은 .mjs 를 javascript/esm 으로 고정해 CommonJS 를 막는다1 — type 을 직접 주면 그 기본 규칙을 건너뛴다2.

configureWebpack: {
    module: {
      rules: [
        {
          test: /\.mjs$/,
          include: /node_modules/,
          type: 'javascript/auto',
        },
      ],
    },
  },

Footnotes

  1. Module Methods | webpack: “.mjs or .js with "type": "module" in package.json” → “No CommonJS allowed, for example, you can’t use require, module.exports or exports”. webpack 4 기본 규칙: { test: /\.mjs$/i, type: "javascript/esm" } ↩

  2. Module | webpack: “Rule.type sets the type for a matching module. This prevents defaultRules and their default importing behaviors from occurring.” ↩

#292

imagemin을 사용하려고 하는데 module로 라이브러리가 업데이트 되어서 찾아본 내용. 혼란스러운 부분도 있지만 성숙해지는 과정이라고 본다.


Footnotes

  1. esm 배경과 tsup, unbuild 라는 두개의 해결방법을 소개해주고 있다. ↩

#58