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).
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 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
- Add
export {}; - Set
"moduleDetection": "force" - Use
.d.tsfor global declarations
Detailed fix by platform
TypeScript
export {}; // at the end of the file
How to diagnose
- File — Has export/import?
- Flag — isolatedModules?
- 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:
Similar errors
- Cannot find module './App.vue' or its corresponding type declarations TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations.
- ERR_IMPORT_ATTRIBUTE_MISSING TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module needs an import attribute of "type: json"
- ERR_PACKAGE_PATH_NOT_EXPORTED Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './x' is not defined by "exports"
Most viewed in TypeScript
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 5 Nov 2026