더북(TheBook)

예전에는 package.json의 main 속성에 파일의 진입점을 표시해주었습니다. main 속성이 index.js라면 import 'npmtest'를 할 때 index.js 파일을 불러옵니다. 그런데 지금은 CommonJS 모듈이라면 index.js를, ES 모듈이라면 index.mjs를 불러와야 합니다. 하지만 main 속성에는 하나의 파일만 적을 수 있습니다. 이 문제를 해결하기 위해서 노드는 package.json에 exports 속성을 추가하게 되었습니다. package.json 파일을 다음과 같이 수정합니다.

package.json

{
  ...
  "main": "index.js",
  "exports": {
    ".": {
      "import": "./index.mjs",
      "require": "./index.js",
      "default": "./index.js"
    },
    "./package.json": "./package.json"
  },
  "scripts": {
...
}