问题描述
我的打字稿编译有问题。 smbd面对过吗?
node_modules/@types/node/index.d.ts(20,1):错误TS1084:无效 “引用”指令语法。
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"
解决方法
我遇到了同样的问题,发现解决方案是将 typescript 从当前版本更新到最新版本。
在 package.json 文件中进行如下更改:
"devDependencies": {
"typescript": "^3.9.7"
}
现在 "npm install typescript" ,它将升级到最新版本。然后运行“ng serve”,编译成功。
,我遇到了同样的错误。我在package.json中使用了固定版本“ @ types / node”:“ 7.0.7”,并使它正常工作。
,有同样的问题。打开文件../ node_modules/@types/node/index.d.ts
并删除第三个斜杠
// <reference lib="es2015" />
再次编译
,它对我有用
为 TypeScript 版本检查标签。
运行 npm dist-tag ls @types/node
并查找您当前的打字稿版本。
然后安装支持打字稿的@types/node 版本 in my case I had to install 14.0.1 version
参考:https://github.com/DefinitelyTyped/DefinitelyTyped/issues/47250#issuecomment-687701880
,发生相同的错误,并且解决方法是使用以前的版本,检查package.json中@ types / node的版本,然后查看是否具有最新版本。 您可以在此处检查:Issue Tracker,因为它暗示有新更新。
,我的解决方案是将打字稿版本更改为“>=2.7.3”。 我认为该版本可能取决于其他软件包。 可能需要尝试几次才能获得正确的版本。 并且不要忘记运行安装。
,我遇到了同样的问题,发现解决方案是将 typescript 从当前版本更新到最新版本。
在 package.json 文件中进行如下更改:
"devDependencies": {
"typescript": "^3.9.7"
}
现在npm install typescript
,它将升级到最新版本。然后运行“ng serve”,编译成功。