如何强制 tsc 忽略 node_modules 文件夹?

新手上路,请多包涵

我正在使用 tsc 构建任务。不幸的是,我总是从节点模块文件夹中得到相同的错误

Executing task: .\node_modules\.bin\tsc.cmd --watch -p .\tsconfig.json <
node_modules/@types/node/index.d.ts(6208,55): error TS2304: Cannot find name 'Map'.
node_modules/@types/node/index.d.ts(6215,55): error TS2304: Cannot find name 'Set'.
node_modules/@types/node/index.d.ts(6219,64): error TS2304: Cannot find name 'Symbol'.
node_modules/@types/node/index.d.ts(6225,59): error TS2304: Cannot find name 'WeakMap'.
node_modules/@types/node/index.d.ts(6226,59): error TS2304: Cannot find name 'WeakSet'.
10:13:18 - Compilation complete. Watching for file changes.

我已经将目录添加到忽略 tsconfig.json


    {
      "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "strict": false,
        "noImplicitAny": false,
        "strictPropertyInitialization": false,
        "esModuleInterop": true,
      },
      "include": [
        "src/*"
      ],
      "exclude": [
        "node_modules",
        "./node_modules",
        "./node_modules/*",
        "./node_modules/@types/node/index.d.ts",
      ]
    }

我做错了什么?我应该怎么做才能忽略这些错误?

我正在使用 VsCode 和 tsc 版本 2.9.2

原文由 Daniel Santos 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2k
1 个回答

Quickfix 是跳过检查

{
  "compilerOptions": {
    "skipLibCheck": true
  },
}

原文由 Daniel Swiegers 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题