TS1378

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.

Broken Code ❌

tsconfig.json

1
2
3
4
5
6
7
8
9
{
"compilerOptions": {
"lib": ["es2017"],
"module": "commonjs",
"outDir": "dist",
"rootDir": "src",
"target": "es6"
}
}

Fixed Code ✔️

tsconfig.json

1
2
3
4
5
6
7
8
9
{
"compilerOptions": {
"lib": ["es2017"],
"module": "esnext",
"outDir": "dist",
"rootDir": "src",
"target": "es2017"
}
}