【问题标题】:Cannot find name 'AbortSignal' during npm run build在 npm 运行构建期间找不到名称“AbortSignal”
【发布时间】:2022-01-01 21:01:08
【问题描述】:
node_modules/axios/index.d.ts:93:12 - error TS2304: Cannot find name 'AbortSignal'.

93   signal?: AbortSignal;
              ~~~~~~~~~~~


Found 1 error.

在为 node typescript 项目尝试 npm run build comand 时,我遇到了与 axio 包相关的错误。在使用 axio 之前,npm run build 工作正常。

【问题讨论】:

    标签: typescript npm build axios


    【解决方案1】:

    您需要将 DOM 添加到 tsconfig.json 中的 lib 数组中:

    "lib": [
          "es2018",
          "DOM"
        ],
    

    【讨论】:

    • 我刚刚降级了 axios 包,现在问题解决了,你能详细说明一下你的解决方案吗,当我把上面提到的代码放在 tsconfig.json 上会发生什么?
    • 因为它只是类型提示,除了修复你的构建问题。这是github.com/axios/axios/issues/4124 的 axios 问题。仅供参考,升级到 nodejs 16 也将修复它。
    【解决方案2】:

    您还可以在compilerOptions 下将"skipLibCheck": true, 添加到您的tsconfig.json。 这将忽略 node_modules 下的库中存在的错误

    【讨论】:

      猜你喜欢
      • 2019-08-20
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 2019-05-26
      相关资源
      最近更新 更多