node.js - node_modules/@types/node/index.d.ts(20,1):错误 TS1084:无效的 'reference' 指令语法
我在 TypeScript 编译时遇到了问题。有人也收到过这个错误吗?
node_modules/@types/node/index.d.ts(20,1):错误 TS1084:无效的 'reference' 指令语法。
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./app",
"target": "es6",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"listFiles": false,
"skipLibCheck": true
},
"include": [
"./app/**/*.ts"
]
}
package.json 中的 TypeScript 版本:"typescript": "^2.6.1"
答案#1
遇到了同样的问题。打开文件 ../node_modules/@types/node/index.d.ts
并移除第三个斜杠
// <reference lib="es2015" />
再次编译
答案#2
我遇到了同样的错误。我在 package.json 中使用了固定版本 "@types/node": "7.0.7",并让它正常工作了。
答案#3
我也遇到过同样的问题,发现解决方法是将 TypeScript 从当前版本更新到最新版本。
在 package.json 文件中进行如下更改:
"devDependencies": {
"typescript": "^3.9.7"
}
现在运行 "npm install typescript",它会升级到最新版本。然后运行 "ng serve",它将成功编译。
答案#4
更新TypeScript
npm install typescript@latest --save-dev
