【问题标题】:Cannot find type definition file for 'bson'. The file is in the program because: Entry point for implicit type library 'bson'找不到“bson”的类型定义文件。该文件在程序中,因为:隐式类型库“bson”的入口点
【发布时间】:2022-03-24 16:39:37
【问题描述】:

我设置了新的 Typescript/React 项目,在 tsconfig.json 文件中收到此错误消息

"找不到 'bson' 的类型定义文件。 该文件在程序中,因为: 隐式类型库 'bson' 的入口点"

任何想法。

这是我的 tsconfig.json


{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

【问题讨论】:

  • 请发布您的 tsconfig.json 文件和任何其他可能相关的代码
  • 添加了请看。

标签: reactjs typescript next.js eslint


【解决方案1】:

在github找到解决方案

当 typeRoots 目录的子目录(在本例中为 node_modules/@types)不包含 index.d.ts 时会发生这些错误

对我来说,问题在于我正在创建一个库,该库确实导出了一堆 interfaces 和 types

这是一个例子

types-folder
├─── index.d.ts
└─── child-folder
     └─── index.d.ts // <-- Mendatory

【讨论】:

    猜你喜欢
    • 2022-11-01
    • 1970-01-01
    • 2017-06-09
    • 2016-04-06
    • 2016-07-08
    • 2018-07-20
    • 2021-04-01
    • 1970-01-01
    • 2022-11-03
    相关资源
    最近更新 更多