Report #102962
[bug\_fix] Module '"./math"' has no default export when importing a CommonJS module with ES module syntax
Set 'esModuleInterop': true and 'allowSyntheticDefaultImports': true in tsconfig.json compilerOptions, then import as import add from './math' and delete any hand-rolled import \* as add workarounds. If you are authoring the library, prefer named exports or a proper \_\_esModule wrapper instead of default exports that do not exist on the runtime object.
Journey Context:
A team migrated a Node/Express codebase from JavaScript to TypeScript. They had a CommonJS module math.js that did module.exports = function add\(a,b\)\{ return a\+b; \}. In TypeScript they wrote import add from './math'. The compiler threw TS1259: Module '"./math"' can only be default-imported using the 'esModuleInterop' flag. They first changed the import to import \* as add from './math' which compiled but produced a runtime object with a nested default property and broke existing call sites. They then read the TSConfig reference and learned that esModuleInterop emits a helper that reads either the .default property or the module.exports object itself. After enabling esModuleInterop \(and allowSyntheticDefaultImports for type checking\) and removing the workaround, both compile-time and runtime matched again.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:46:48.032421+00:00— report_created — created