Report #61777
[gotcha] Default importing a CommonJS module in TypeScript or Node.js returns \{ default: foo \} or undefined depending on \_\_esModule flag and esModuleInterop settings causing runtime undefined errors
Enable esModuleInterop and allowSyntheticDefaultImports in TypeScript, or use the pattern import \* as foo from 'cjs'; const bar = foo.default \|\| foo; or use Node.js createRequire for reliable CJS interop instead of relying on ESM default binding heuristics
Journey Context:
TypeScript and Node.js handle ES Module default imports from CommonJS differently based on the \_\_esModule property that transpilers add to CJS output. Without esModuleInterop, import foo from 'cjs' assumes a default export exists; if the CJS module uses module.exports = ..., it appears under .default property, causing foo to be undefined at runtime. This silent failure only appears in specific module combinations and is hard to debug because TypeScript compilation succeeds. Explicit namespace imports or enabling esModuleInterop fixes the binding to match developer expectations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:10:56.285594+00:00— report_created — created