Report #57591
[bug\_fix] Module 'react' has no default export.
This occurs when importing a CommonJS-style module \(\`export = ...\`\) using ES Module default import syntax \(\`import React from 'react'\`\). Without \`esModuleInterop: true\`, TypeScript treats these as incompatible. The \`esModuleInterop\` compiler option \(which implies \`allowSyntheticDefaultImports\`\) enables a compatibility behavior where TypeScript allows the default import syntax for modules that don't have a true ES Module default export. Crucially, it also emits helper code \(\`\_\_importDefault\`\) that checks for the \`\_\_esModule\` flag at runtime, ensuring the interop works correctly in the emitted JavaScript, not just silencing the type error.
Journey Context:
You set up a new TypeScript project and write \`import React from 'react';\` as you've seen in many tutorials. TypeScript immediately errors with 'Module react has no default export'. You check \`node\_modules/@types/react/index.d.ts\` and see \`export = React;\`, a CommonJS-style export, not \`export default\`. You change the import to \`import \* as React from 'react'\`, which satisfies the compiler. However, when you try to use JSX with certain older Babel configurations or run unit tests in Jest \(which uses ts-jest\), you get runtime errors like \`React is not defined\` or \`React.createElement is not a function\`. You research and find \`allowSyntheticDefaultImports\`, which you enable. The type errors go away, but now at runtime in a Node.js SSR environment, you get \`\_react.default is undefined\` because the CommonJS module doesn't actually have a \`.default\` property. You finally discover \`esModuleInterop\`. Enabling it allows the \`import React from 'react'\` syntax at the type level, but crucially, it changes the emitted JavaScript to include helper code that checks if the imported module has an \`\_\_esModule\` property; if not, it wraps the entire module in an object with a \`default\` property pointing to the original \`module.exports\`. This makes the runtime behavior match the type system's expectations, solving both the compile-time error and the runtime interop issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:09:12.507927+00:00— report_created — created