【问题标题】:node_modules/@types/node/index.d.ts(20,1): error TS1084: Invalid 'reference' directive syntaxnode_modules/@types/node/index.d.ts(20,1):错误 TS1084:无效的“参考”指令语法
【发布时间】:2020-12-22 12:05:03
【问题描述】:

我遇到了打字稿编译问题。有其他人收到此错误吗?

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": "^2.6.1"

【问题讨论】:

    标签: node.js typescript compilation tsconfig


    【解决方案1】:

    有同样的错误,修复是使用以前的版本,检查你在 package.json 中的 @types/node 的版本,看看你是否有最新的。 您可以在这里查看:https://www.npmjs.com/package/@types/node,因为它表明有新的更新。

    【讨论】:

    • 投了你一票,因为你比上面的答案领先了半个多小时,更新到最新版本(假设问题已解决)比仅仅构建更好的做法到特定版本。另外,我不明白为什么当问题显然与@types/node有关时,所有建议更新打字稿的答案都得到了赞成。
    【解决方案2】:

    我遇到了同样的错误。我在 package.json 中使用了固定版本 "@types/node": "7.0.7" 并使其正常工作。

    【讨论】:

    • 我用 "@types/node": "7.0.7" 更新了我的 package.json,然后运行以下命令:npm install --save @types/node。之后,我能够成功运行 npm start 。谢谢!
    【解决方案3】:

    有同样的问题。打开文件 ../node_modules/@types/node/index.d.ts

    并删除第三个斜线

    // <reference lib="es2015" />
    

    再次编译

    【讨论】:

    • 但是下次你清除 node_modules 并重新安装,或者在另一台机器上安装时,这个就没有了,你需要记住再做一次......
    • 您可以删除第三个斜线,但由于不建议更改任何 node_modules 文件夹的内容,最好将 typescript 版本更新为最新版本。
    • 我的测试有问题,经过数小时的搜索,这就像一个魅力 =)
    • 降级到 "@types/node": "^7.0.7" 看起来是更明智的解决方案
    • 之前:/// 之后://
    【解决方案4】:

    我的解决方案是将 typescript 版本更改为 '>=2.7.3'。 我认为该版本可能取决于其他软件包。 可能需要尝试几次才能获得正确的版本。 不要忘记运行安装。

    【讨论】:

      【解决方案5】:

      我也遇到过同样的问题,发现解决办法是将 typescript 从当前版本更新到最新版本。

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

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

      现在 "npm install typescript" ,它将升级到最新版本。然后运行“ng serve”,编译成功。

      【讨论】:

        【解决方案6】:

        我也遇到过同样的问题,发现解决办法是将 typescript 从当前版本更新到最新版本。

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

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

        现在npm install typescript,它将升级到最新版本。然后运行“ng serve”,编译成功。

        【讨论】:

          【解决方案7】:

          它对我有用 为 TypeScript 版本检查您的标签。 运行npm dist-tag ls @types/node 并查找您当前的打字稿版本。

          然后安装支持 typescript 的 @types/node 版本 in my case I had to install 14.0.1 version

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

          【讨论】:

            【解决方案8】:

            更新 TypeScript

            npm install typescript@latest --save-dev
            

            【讨论】:

            • 可以了,基本需要更新tS
            【解决方案9】:

            尝试降级@type/node

            我遇到了同样的问题

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

            我降级到低版本,编译成功

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

            【讨论】:

              猜你喜欢
              • 2017-04-05
              • 2017-07-08
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2022-12-15
              • 2022-12-16
              • 2019-03-26
              • 2017-04-13
              相关资源
              最近更新 更多