Skip to content
Latchkey

TS1208: isolatedModules - file cannot be compiled - in CI

Under isolatedModules, every file must be a module, but this file has no imports or exports so it is treated as a global script.

What this error means

Type-checking fails with TS1208 telling you to add an import, export, or empty export.

tsc
src/constants.ts(1,1): error TS1208: 'constants.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.

Common causes

How to fix it

Add an empty export

  1. Append export {} to make the file a module
ts
export {}

Export the file's symbols

  1. If the file defines reusable values, export them instead of keeping them global
ts
export const API_URL = "/api"

How to prevent it

  • Author every file as a module (import/export) when isolatedModules is on, which single-file transpilers require.

Frequently asked questions

What causes "TS1208 isolatedModules"?
Type-checking fails with TS1208 telling you to add an import, export, or empty export.
How do I fix TS1208 isolatedModules?
Add an empty export

Related guides

References

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