簡體   English   中英

node_modules/@types/node/index.d.ts(20,1):錯誤 TS1084:無效的“引用”指令語法

[英]node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntax

我的 typescript 編譯有問題。 有沒有其他人收到這個錯誤?

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"

有同樣的問題。 打開文件 ../node_modules/@types/node/index.d.ts

並刪除第三個斜線

// <reference lib="es2015" />

再次編譯

我得到了同樣的錯誤。 我在 package.json 中使用了固定版本 "@types/node": "7.0.7" 並使其正常工作。

我遇到了同樣的問題,發現解決方案是將打字稿從當前版本更新到最新版本。

在 package.json 文件中進行如下更改:

"devDependencies": {
     "typescript": "^3.9.7"
 }

現在 "npm install typescript" ,它將升級到最新版本。 然后運行“ng serve”,編譯成功。

它對我有用,可以檢查 TypeScript 版本的標簽。 運行npm dist-tag ls @types/node並查找您當前的打字稿版本。

然后安裝支持打字稿的@types/node 版本,在我的情況下我必須安裝 14.0.1 版本

參考: https : //github.com/DefinitelyTyped/DefinitelyTyped/issues/47250#issuecomment-687701880

有同樣的錯誤,修復是使用以前的版本,檢查你在 package.json 中 @types/node 的版本,看看你是否有最新的版本。 您可以在此處查看: https : //www.npmjs.com/package/@types/node,因為它似乎有新的更新。

我的解決方案是將打字稿版本更改為“>=2.7.3”。 我認為該版本可能取決於其他軟件包。 可能需要嘗試幾次才能獲得正確的版本。 並且不要忘記運行安裝。

更新打字稿

npm install typescript@latest --save-dev

嘗試降級@type/node

我有同樣的問題

"devDependencies": {
    "@types/node": "12.20.42",
}

我將其降級為較低版本並成功編譯

"devDependencies": {
    "@types/node": "12.19.12",
}

我遇到了同樣的問題,發現解決方案是將打字稿從當前版本更新到最新版本。

在 package.json 文件中進行如下更改:

"devDependencies": {
     "typescript": "^3.9.7"
 }

現在npm install typescript ,它將升級到最新版本。 然后運行“ng serve”,編譯成功。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM