Report #102457
[bug\_fix] TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.
isolatedModules requires each file to be compilable independently, but ambient const enum values are inlined at compile time using type information from other files, which single-file transpilers such as Babel, SWC, or ts.transpileModule cannot do. Replace declare const enum Foo \{ ... \} with a regular enum Foo \{ ... \} or an object literal plus a string/numeric union type. Alternatively, if you only use tsc and do not need Babel/SWC, you can disable isolatedModules.
Journey Context:
Your Next.js or create-react-app project uses Babel to transpile TypeScript, which forces isolatedModules: true. You install a library that ships .d.ts files containing declare const enum ViewState \{ ... \}, or you write one yourself. Compilation fails with TS1209: Ambient const enums are not allowed when '--isolatedModules' is provided. You wonder why a declaration file causes an error. The reason is that const enum members are replaced by their literal values during emit; a single-file transpiler does not have the enum's values available, so it cannot safely inline them. The robust fix is to stop exporting ambient const enums from libraries and use a regular enum, which emits a real object, or an as const object plus a derived union type. Once you make that change, Babel/SWC and tsc agree.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T04:54:11.871967+00:00— report_created — created