The xxxx library may need to update its package.json or typings.ts

이용규·2023년 7월 20일
0

npm으로 라이브러리를 설치하고, import 했더니 듣도 보도 못한 에러가 발생했다.

일단은 침착하게 문구를 살펴보고, 마지막 줄에 있는 문장을 검색해보니 스택오버플로우의 질문글을 찾을 수 있었다.
답변을 보니, 라이브러리의 "exports" 필드가 존재한다면, "types" 필드에 있는 d.ts 파일은 사용되지 않는다는 것이다.
따라서, "exports"에 있는 "." 필드에 "types"를 필드에 d.ts 파일을 명시해주면 된다고 한다.
(참고로 package.json 파일에는 주석을 넣으면 안 된다!)

{
  "exports": {
    ".": {
      // Specify types first
      "types": "./dist/index.d.ts",
      "import": "./dist/rd-component.es.js",
      "require": "./dist/rd-component.umd.js"
    },
    "./dist/style.css": {
      "import": "./dist/style.css",
      "require": "./dist/style.css"
    }
  },
}

exports -> . -> types 에 d.ts 파일 위치를 명시해주니 바로 해결이 됐다.
스택오버플로우 조아....!
참조: https://stackoverflow.com/questions/76211877/the-xxxx-library-may-need-to-update-its-package-json-or-typings-ts

profile
Next.js 개발자 https://twitter.com/YG1ee

1개의 댓글

comment-user-thumbnail
2023년 7월 20일

아주 유익한 내용이네요!

답글 달기