Report #57762
[bug\_fix] Module 'express' can only be default-imported using the 'esModuleInterop' flag. ts\(1259\)
Enable 'esModuleInterop': true in tsconfig.json. This flag allows default imports from modules with no default export \(CommonJS modules using 'module.exports = ...'\) by synthesizing a default export. Alternatively, use the CommonJS-style import 'import express = require\('express'\);' which works without flags and accurately represents the module loading semantics.
Journey Context:
Developer starts a new Node.js API project, installing Express and @types/express. They write 'import express from 'express';' following modern ES module syntax. The compiler errors with the esModuleInterop message. They try 'import \* as express from 'express'' which compiles but then 'express\(\)' throws 'TypeError: express is not a function' at runtime because 'import \*' creates a namespace object, not the function itself. They investigate and learn that CommonJS modules export a single value via 'module.exports', which is not the same as ES modules' default export. Without esModuleInterop, TypeScript treats the module as having no default export. The flag enables the synthetic default import behavior that aligns Babel/webpack behavior with TypeScript, allowing the import to resolve to the CommonJS module.exports value.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:26:41.185014+00:00— report_created — created