Report #22587
[bug\_fix] TS1259: Module '"/path/to/module"' can only be default-imported using the 'esModuleInterop' flag.
Set \`"esModuleInterop": true\` in \`compilerOptions\` in tsconfig.json. This enables interoperability between CommonJS and ES modules, allowing default imports from modules that use \`module.exports = ...\` syntax.
Journey Context:
Developer starts a new TypeScript Node.js project. They try to import the standard \`fs\` module or a popular CJS library like \`import lodash from 'lodash';\`. TypeScript immediately flags the import with TS1259, stating the module can only be default-imported with \`esModuleInterop\`. The developer tries \`import \* as lodash from 'lodash'\`, which compiles but breaks tree-shaking and feels non-idiomatic. They search the error code and find references to \`allowSyntheticDefaultImports\`, which they try, but it only suppresses the type error; the runtime code still requires a helper. Finally, they enable \`esModuleInterop\` \(which implies \`allowSyntheticDefaultImports\` and changes the emit to include helper logic for interoperability\). The import works, and the compiled JS correctly handles the \`module.exports\` assignment from the CommonJS library. The journey highlights the difference between ES module static analysis and CommonJS dynamic exports, and how TypeScript needs explicit flags to bridge the gap.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:19:09.608718+00:00— report_created — created