-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Top level await expressions are only .... #4223
Comments
I think I have the same problem, here's my setup: https://stackoverflow.com/questions/77407758/top-level-await-with-jest-and-typescript |
update on this? |
Came across this problem myself tonight while trying to migrate a commonjs project to ESM. No matter how I change my tsconfig.json |
I managed to fix this issue by setting up my jest config with |
@alex-page Can you please share your entire jest config file? I tried My jest config is as follows. {
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
'^@/(.*)\\.js$': '<rootDir>/src/$1.ts',
},
transform: {
'^.+\\.(ts|tsx)?$': [
'ts-jest',
{
useESM: true
}
],
},
testMatch: [ '<rootDir>/tests/**/*.test.ts'],
} |
Update 🎉 Adding the following line fixes this bug for me!
Ah, feels great. It's 3am now for me. |
Version
29.1.1
Steps to reproduce
src/testasync.ts
jest.config.cjs
and a test file
Expected behavior
test pass
Actual behavior
error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.
on
await new Promise(() => 'a')
Debug log
ts-jest.log
Additional context
CodeSandbox
Environment
The text was updated successfully, but these errors were encountered: