如何解决 TypeScript 编译器错误“命名空间‘NodeJS’没有导出成员‘全局’”?

问题描述

问题:如何解决 Typescript 编译器 (tsc) 错误命名空间‘NodeJS’没有导出成员‘全局’”? >

在运行 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
Jest 版本:26.5.3

解决方法

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

降级到 @types/node v15.14.0 似乎解决了我的问题。

,

通过将 "skipLibCheck": true 添加到我的 tsconfig 中,我能够解决此问题。

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