【问题标题】:Fixing TS2688: Cannot find type definition file in node_modules修复 TS2688:在 node_modules 中找不到类型定义文件
【发布时间】:2020-08-27 10:03:24
【问题描述】:

运行 tsc 时,我收到很多 TS2688: Cannot find type definition file for 'someLibrary' 这些库来自node_modules。我试图在 tsconfig 中排除 node_modulesskipLibCheck,但它们都不适合我。知道为什么会这样吗?

这是我的 tsconfig.json

{
  "ts-node": {
    "files": true,
    "emit": true,
    "compilerHost": true
  },
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "es2016",
    "sourceMap": true,
    "typeRoots" : ["./node_modules","./node_modules/@types"],
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "commonJS",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
  },
  "exclude": [
    "node_modules"
  ]
}

【问题讨论】:

  • 如果你使用vscode,可以按ctrl+shift+p,选择Restart TS Server

标签: typescript tsc tsconfig


【解决方案1】:

问题是错误的typeRoots。应该使用默认的./node_modules/@types

【讨论】:

    猜你喜欢
    • 2021-01-11
    • 2019-07-10
    • 2021-05-14
    • 1970-01-01
    • 2022-10-20
    • 2018-02-24
    • 2018-03-09
    • 2021-09-14
    • 2019-05-11
    相关资源
    最近更新 更多