Report #3616
[bug\_fix] This module is declared with 'export =', and can only be used with a require\(\) call or by using a 'esModuleInterop' flag and allowing synthetic default imports.
Enable \`esModuleInterop: true\` \(and optionally \`allowSyntheticDefaultImports: true\`, though esModuleInterop implies it\) in tsconfig.json compilerOptions. The root cause is that the target module uses CommonJS \`module.exports = ...\` \(export equals\), which TypeScript models as \`export =\`. Without esModuleInterop, you cannot use ES6 default import syntax \(\`import foo from 'foo'\`\) on these modules; you must use \`import \* as foo\` or \`import foo = require\('foo'\)\`.
Journey Context:
You're migrating a Node.js project from JavaScript to TypeScript. You install \`@types/express\` and write \`import express from 'express';\`. Immediately, TypeScript underlines \`express\` with error TS1259: "This module is declared with 'export =', and can only be used with a require\(\) call..." You try changing it to \`import \* as express from 'express';\` which fixes the error but breaks your middleware typing elsewhere because \`express\` is now the namespace, not the callable function. You search online and find conflicting advice about \`allowSyntheticDefaultImports\`. You try setting \`allowSyntheticDefaultImports: true\` but the error persists. You then find the crucial distinction: \`allowSyntheticDefaultImports\` only affects type checking, not emit, and doesn't change the module resolution rules for \`export =\`. You need \`esModuleInterop: true\`. You add it to tsconfig.json, and suddenly \`import express from 'express';\` works perfectly because TypeScript now treats the CommonJS module as if it has a default export, emitting the appropriate helper code for interoperability. The root cause was that without esModuleInterop, TypeScript enforces the ES module spec strictly, which doesn't map \`export =\` to \`default\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T17:46:00.174299+00:00— report_created — created