Skip to content
Latchkey

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

  1. Use an ESM module setting and target es2017+
tsconfig.json
{
  "compilerOptions": {
    "module": "esnext",
    "target": "es2022"
  }
}

Wrap the await instead

  1. 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

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card