【问题标题】:How can I resolve the TypeScript Compiler error "Namespace 'NodeJS' has no exported member 'Global'"?如何解决 TypeScript 编译器错误“命名空间 'NodeJS' 没有导出的成员 'Global'”?
【发布时间】:2021-09-16 14:26:33
【问题描述】:

问题:如何解决 Typescript 编译器 (tsc) 错误“命名空间 'NodeJS' 没有导出的成员 'Global'”?

在运行 tsc 时,我突然在“遗留”(非新)项目中看到以下错误:

node_modules/expect/node_modules/@jest/types/build/Global.d.ts:85:62 - error TS2694: Namespace 'NodeJS' has no exported member 'Global'.

85 export interface Global extends GlobalAdditions, Omit<NodeJS.Global, keyof GlobalAdditions> {
                                                                ~~~~~~

我尝试添加安装@types/node 并将"types": ["node"] 添加到我的tsconfig(如this SO post 中的建议),但这没有帮助。

节点版本:12.18.4
笑话版:26.5.3

【问题讨论】:

    标签: javascript node.js jestjs tsc


    【解决方案1】:

    这是一个已知错误:https://github.com/facebook/jest/issues/11640

    降级到@types/node v15.14.0 似乎可以解决我的错误。

    【讨论】:

    • jest 升级到 v27.1.0 为我修复了它。
    【解决方案2】:

    我可以通过将"skipLibCheck": true 添加到我的tsconfig 来解决此问题。

    TFM:https://www.typescriptlang.org/tsconfig#skipLibCheck

    【讨论】:

    • 我对这个问题的其他答案很感兴趣,尤其是如果他们能解释问题的根本原因。
    猜你喜欢
    • 2021-10-09
    • 2021-06-05
    • 2019-10-09
    • 1970-01-01
    • 1970-01-01
    • 2019-02-07
    • 2023-03-13
    • 2021-11-11
    • 2018-03-16
    相关资源
    最近更新 更多