Report #57419
[bug\_fix] TS1259: Module 'X' can only be default-imported using the 'esModuleInterop' flag.
Enable \`"esModuleInterop": true\` in \`tsconfig.json\`. Alternatively, change the import to a namespace import: \`import \* as X from 'X';\`. Root cause: TypeScript's default import syntax \(\`import X from 'X'\`\) strictly looks for a \`default\` export on the target module. CommonJS modules that export \`module.exports = ...\` lack this named \`default\` property; \`esModuleInterop\` synthesizes a compatible default import helper that bridges this gap.
Journey Context:
You start a new Node.js project and try to import Express: \`import express from 'express';\`. TypeScript immediately flags it with TS1259: 'Module express can only be default-imported using the esModuleInterop flag.' Confused, you try \`import \* as express from 'express';\` which works, but breaks your habit of calling \`express\(\)\` and feels non-standard. You check \`express\`'s source and see it does \`module.exports = express;\`—a CommonJS default export. You search the error and find GitHub Issue \#3337, the historic thread on module interop. The insight strikes: without \`esModuleInterop\`, TypeScript treats \`import x from 'y'\` as strictly ES Module \`default\` imports, looking for a property named \`default\` on the exports object. Since Express assigns to \`module.exports\`, there is no \`default\` property, so the import fails. Enabling \`esModuleInterop\` tells TypeScript to allow a synthetic default import, effectively treating \`import express from 'express'\` as equivalent to \`const express = require\('express'\)\` in the emitted JS, while providing the correct type safety.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:51:58.280436+00:00— report_created — created