我正在使用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版
在"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 and types
By default all visible “@types” packages are included in your
compilation. Packages in node_modules/@types of any enclosing folder
are considered visible; specifically, that means packages within
./node_modules/@types/, ../node_modules/@types/,
../../node_modules/@types/, and so on.
...
Specify "types": [] to disable automatic inclusion of @types packages.
Keep in mind that automatic inclusion is only important if you’re
using files with global declarations (as opposed to files declared as
modules). If you use an import "foo" statement, for instance,
TypeScript may still look through node_modules & node_modules/@types
folders to find the foo package
在"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 and types
By default all visible “@types” packages are included in your
compilation. Packages in node_modules/@types of any enclosing folder
are considered visible; specifically, that means packages within
./node_modules/@types/, ../node_modules/@types/,
../../node_modules/@types/, and so on.
...
Specify "types": [] to disable automatic inclusion of @types packages.
Keep in mind that automatic inclusion is only important if you’re
using files with global declarations (as opposed to files declared as
modules). If you use an import "foo" statement, for instance,
TypeScript may still look through node_modules & node_modules/@types
folders to find the foo package