What is 'isolatedModules' and why do some tools (like Babel, esbuild, or swc) require it to be enabled?
Short answer
isolatedModules ensures every file can be safely transpiled INDEPENDENTLY, one file at a time, without needing full cross-file type information — some fast, non-typechecking compilers (Babel, esbuild) work this way for speed, and certain TypeScript patterns (like re-exporting…
Advertisement
AModel answer
isolatedModules ensures every file can be safely transpiled INDEPENDENTLY, one file at a time, without needing full cross-file type information — some fast, non-typechecking compilers (Babel, esbuild) work this way for speed, and certain TypeScript patterns (like re-exporting only a type without 'export type') break that single-file assumption, so this flag catches them at typecheck time.
// With isolatedModules: true, this needs 'export type' explicitly:
export type { User } from './types'; // OK
// export { User } from './types'; // Error if User is type-only and isolatedModules is onReal-world example
Ensuring a codebase remains compatible with a fast Babel or esbuild-based build pipeline that doesn't do full program-wide type analysis.
Likely follow-ups
- Does isolatedModules perform any type-checking itself, or is it purely a structural/syntax constraint?
Related topics