TS1378: Top-level await requires module/target - in CI
You used await at module top level, but the tsconfig module/target settings do not permit it.
What this error means
Type-checking fails with TS1378 listing the module and target values required for top-level await.
tsc
src/boot.ts(3,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.Common causes
How to fix it
Set a compatible module and target
- Use an ESM module setting and target es2017+
tsconfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "es2022"
}
}Wrap the await instead
- If you must keep commonjs, move the await into an async IIFE
ts
(async () => {
await init()
})()How to prevent it
- Align module/target with the language features you use, or avoid top-level await under CommonJS.
Frequently asked questions
What causes "TS1378 top-level await"?
Type-checking fails with TS1378 listing the module and target values required for top-level await.
How do I fix TS1378 top-level await?
Set a compatible module and target
Related guides
TS2307: Cannot find module - in CIFix "error TS2307: Cannot find module 'x' or its corresponding type declarations" when tsc runs in CI - a mis…
TS5023: Unknown compiler option - in CIFix "error TS5023: Unknown compiler option 'x'" when tsc runs in CI - a typo, a removed option, or an option…
TS1208: isolatedModules - file cannot be compiled - in CIFix "error TS1208: ... cannot be compiled under '--isolatedModules' because it is considered a global script…