TS1208: File cannot be compiled under '--isolatedModules' because it is considered a global script file TypeScript Origin: On your device Last updated 5 Nov 2026

TypeScript: error TS1208: 'index.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement

With isolatedModules, every file must be a module (have an import or export).

Exact message you may see error TS1208: 'index.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file.cannot be compiled under '--isolatedModules' because it is considered a global script fileTS1208 isolatedModules global script fileAdd an import, export, or an empty 'export {}' statement to make it a module
Seen on: TypeScript

Meaning

Add export {}; to the file, or make it a real module. Required by Babel/SWC/esbuild/Vite/Next compile steps that transpile files one by one. TS 5.0+ with moduleDetection: "force" treats all files as modules.

Common causes

  • File without import/export
  • isolatedModules: true (Vite/Next defaults)
  • Script files for globals/type declarations
  • Scratch/test files
  • Mixed config

⚡ Quick fix

  1. Add export {};
  2. Set "moduleDetection": "force"
  3. Use .d.ts for global declarations

Detailed fix by platform

TypeScript

  1. export {}; // at the end of the file

How to diagnose

  1. File — Has export/import?
  2. Flag — isolatedModules?
  3. Option — moduleDetection?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

Cannot find module './App.vue' or its corresponding type declarations — TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations. (Vue)Cannot find module '.…ERR_IMPORT_ATTRIBUTE_MISSING — TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module needs an import attribute of "type: json" (Node.js)ERR_IMPORT_ATTRIBUTE_…ERR_PACKAGE_PATH_NOT_EXPORTED — Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './x' is not defined by "exports" (Node.js)ERR_PACKAGE_PATH_NOT_…ERR_REQUIRE_ESM — Error [ERR_REQUIRE_ESM]: require() of ES Module not supported (Node.js)ERR_REQUIRE_ESMSyntaxError import — SyntaxError: Cannot use import statement outside a module (Node.js)SyntaxError importTS1005: ';' expected / ',' expected (syntax error) — TypeScript: error TS1005: ';' expected. (TypeScript)TS1005: ';' expected …TS1128: Declaration or statement expected — TypeScript: error TS1128: Declaration or statement expected. (TypeScript)TS1128: Declaration o…TS1192: Module has no default export — TypeScript: error TS1192: Module '"./utils"' has no default export. (TypeScript)TS1192: Module has no…TS1208: F…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.