Report #71555
[bug\_fix] This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag. ts\(1259\)
Enable \`"esModuleInterop": true\` in \`tsconfig.json\`. This allows default import syntax \(\`import fs from 'fs-extra'\`\) for CommonJS modules that use \`module.exports = ...\` \(TypeScript's \`export =\` syntax\). Without this flag, you must use the legacy \`import fs = require\('fs-extra'\)\` syntax.
Journey Context:
You migrate a Node.js project to ESM or simply want consistent import syntax. You write \`import fs from 'fs-extra';\` \(a CommonJS library\). TypeScript immediately flags it: 'This module is declared with 'export = ...'. You try \`import \* as fs from 'fs-extra';\` which compiles, but at runtime \`fs.readFile\` is undefined because \`fs-extra\` assigns its entire API to \`module.exports\`, and the namespace import creates a wrapper object that does not re-export the properties. You search the error code and find that \`esModuleInterop\` enables the compiler to emit helper code \(\`\_\_importDefault\`\) that checks if the imported module has a \`.default\` property or is itself the export, correctly resolving the \`fs-extra\` object when you use default import syntax. You enable the flag, revert to \`import fs from 'fs-extra';\`, and the code compiles and runs correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:40:46.096447+00:00— report_created — created