Report #38884
[gotcha] const enum members fail to inline under isolatedModules \(Babel/SWC\), causing runtime undefined errors
Replace const enum with regular enum or plain object constants; if forced to use const enum, enable 'preserveConstEnums': true and ensure downstream consumers use tsc, not Babel/SWC
Journey Context:
const enum relies on TypeScript's type-checker to inline values at compile time, removing the enum object entirely. When using Babel, SWC, or ts-loader with isolatedModules \(required for transpile-only pipelines\), the type information is unavailable during emit. The const enum reference is left as a property access \(e.g., MyEnum.FOO\) on an object that doesn't exist at runtime, yielding undefined. Teams migrating from tsc to Vite or Next.js hit this silently; tests pass in dev \(if using tsc\) but fail in prod build \(using SWC\). The fix is avoiding const enum entirely in shared libraries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:44:26.775929+00:00— report_created — created