Report #14529
[bug\_fix] isolatedModules flag requires all files to be modules
Add an export \{\} statement to the file to make it a module, or add an actual export for values defined in the file. Alternatively, if the file is meant to be a script modifying global scope, consider if isolatedModules is required, though disabling it limits compatibility with Babel/esbuild.
Journey Context:
Developer enables isolatedModules: true in tsconfig.json because they are using Babel to transpile TypeScript, or because they are using project references which require it. Suddenly, a constants.ts file that simply declares const API\_URL = 'https://api.example.com'; throws error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided, or File '.../constants.ts' is not a module. Developer is confused because they didn't write a namespace. They realize that without any import or export statement, TypeScript treats the file as a script in the global scope, not a module. isolatedModules forbids this because transpilers like Babel process each file independently and cannot handle cross-file namespace merging or global scope pollution. The fix is to add export \{\} at the bottom of constants.ts, which makes it a module \(ESM or CommonJS depending on config\) without exporting anything, or to export the constant itself \(export const API\_URL...\). Developer adds export \{\} and the error disappears. The file is now a module and can be safely transpiled in isolation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:47:40.698400+00:00— report_created — created