我正在使用tsc构建任务。不幸的是,我总是从node modules文件夹中得到相同的错误
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的ignore中
{
"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
发布于 2019-01-20 23:06:55
在“compilerOptions”中添加空的"types“选项:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"strict": false,
"noImplicitAny": false,
"strictPropertyInitialization": false,
"esModuleInterop": true,
"types": []
},
"include": [
"src/*"
],
"exclude": [
"node_modules",
"./node_modules",
"./node_modules/*",
"./node_modules/@types/node/index.d.ts",
]
}来自https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
@types、typeRoots和类型
默认情况下,所有可见的“@types”包都包含在编译中。任何封闭文件夹的node_modules/@type中的包都被认为是可见的;具体地说,这意味着./ node_modules/@types /、../node_modules/@types/、../../node_modules/@types/等等中的包。
..。
指定"types":[]以禁用自动包含@types包。
请记住,只有在使用带有全局声明的文件(而不是声明为模块的文件)时,自动包含才是重要的。例如,如果使用导入" foo“语句,TypeScript可能仍然会在node_modules & node_modules/@types文件夹中查找foo包
https://stackoverflow.com/questions/51634361
复制相似问题