node.js - 如何强制 tsc 忽略 node_modules 文件夹?

标签 node.js typescript tsc tsconfig

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

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

最佳答案

Quickfix 就是跳过检查

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

关于node.js - 如何强制 tsc 忽略 node_modules 文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51634361/

相关文章:

javascript - Elasticsearch 中必须查询(AND)内的嵌套应该查询(OR)

Node.js - Xml 解析

javascript - 使用 TypeScript 作为类型化语言有什么用处?

javascript - TypeScript编译错误 "Unknown file Extension"

node.js - Socket.IO 与 HapiJS 的连接

node.js - 在 MongoDB 和 Node.js 中使用投影进行文本搜索

casting - 在 TypeScript 中构建具有属性的函数对象

angular - 如何订阅变量变化?

javascript - 使用 JsDoc 转换 Typescript

node.js - 使用 npm 定义时 tsc 如何获取其定义