相关疑难解决方法(0)

TS Jest 不会接受 NodeJS 16 和 TypeScript 的顶级等待

我正在尝试将我的 NodeJS 12 和 TypeScript 应用程序更新到 Node16,原因之一是需要使用顶级等待。

\n

更新后代码可以正确编译,但 Jest 不会接受特定的顶级等待代码:

\n
ts-jest[ts-compiler] (WARN) src/xxx.ts:11:17 - error TS1378: Top-level \'await\' expressions are only allowed when the \'module\' option is set to \'es2022\', \'esnext\', \'system\', or \'nodenext\', and the \'target\' option is set to \'es2017\' or higher.\n\n11 const project = await client.getProjectId();\n                   ~~~~~\n FAIL  src/xxx.test.ts\n  \xe2\x97\x8f Test suite failed to run\n\n    Jest encountered an unexpected token\n
Run Code Online (Sandbox Code Playgroud)\n

包.json:

\n
ts-jest[ts-compiler] (WARN) src/xxx.ts:11:17 - error TS1378: Top-level \'await\' expressions are only allowed …
Run Code Online (Sandbox Code Playgroud)

node.js typescript jestjs top-level-await

25
推荐指数
1
解决办法
6865
查看次数

标签 统计

jestjs ×1

node.js ×1

top-level-await ×1

typescript ×1