我正在尝试将我的 NodeJS 12 和 TypeScript 应用程序更新到 Node16,原因之一是需要使用顶级等待。
\n更新后代码可以正确编译,但 Jest 不会接受特定的顶级等待代码:
\nts-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\nRun Code Online (Sandbox Code Playgroud)\n包.json:
\nts-jest[ts-compiler] (WARN) src/xxx.ts:11:17 - error TS1378: Top-level \'await\' expressions are only allowed …Run Code Online (Sandbox Code Playgroud)