Report #11072
[bug\_fix] Cannot access ambient const enums when the '--isolatedModules' flag is provided.
The \`isolatedModules\` compiler option \(enabled by default in projects using Babel, esbuild, swc, or Vite\) requires that each file be transpilable independently without cross-file type information. \`const enum\` values are meant to be inlined at compile time, requiring the compiler to resolve the enum definition across files, which violates the isolated constraint. The fix is to replace \`const enum\` with a regular \`enum\` \(which emits a JavaScript object and supports isolated modules\), or to manually inline the constant values, or to disable \`isolatedModules\` if not required by the build tool \(rare\).
Journey Context:
A developer sets up a new Vite project, which uses \`esbuild\` under the hood. They copy some utility code from an older TypeScript library that uses \`const enum Status \{ Active, Inactive \}\` for performance. Suddenly, the build fails with 'Cannot access ambient const enums when the '--isolatedModules' flag is provided.' The developer checks \`tsconfig.json\` and sees \`isolatedModules: true\` \(or realizes Vite/esbuild implies it\). They try to change it to \`false\`, but the bundler errors out saying it requires isolated modules. They learn that \`const enum\` is a TypeScript-specific optimization that relies on cross-file inlining, incompatible with parallel transpilation. They change \`const enum\` to a regular \`enum\`, which generates a JavaScript object and works fine. The build succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:22:50.631331+00:00— report_created — created