Report #103451
[bug\_fix] Cannot access ambient const enums when the '--isolatedModules' flag is provided. ts\(1209\)
Replace the ambient 'const enum' with a regular 'enum', or if you control the enum source, remove 'const' and enable 'preserveConstEnums'. For third-party libraries that ship ambient const enums, set 'skipLibCheck': true or ask the library to ship non-const enums.
Journey Context:
A Vite project failed to build after I imported an enum from a typings-only package. The error referenced 'isolatedModules'. Vite uses esbuild/swc under the hood, which compile files independently and therefore require '--isolatedModules'. I learned that 'const enum' members are inlined at compile time, which requires the compiler to inspect the declaration across file boundaries—exactly what 'isolatedModules' forbids. Converting the enum to a regular 'enum' made it a real runtime object that could be imported normally, and the build succeeded. The fix works because regular enums emit JavaScript objects that the module system can reference, while const enums rely on cross-file constant inlining.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-11T04:25:19.314718+00:00— report_created — created