Report #42550
[bug\_fix] Module '"/path/to/module"' can only be default-imported using the 'esModuleInterop' flag. \(TS1259\)
Enable \`"esModuleInterop": true\` in tsconfig.json compilerOptions. This allows default import syntax \(\`import mod from 'mod'\`\) to work with CommonJS modules that use \`export =\` or \`module.exports =\`. If you cannot enable this flag, use the CommonJS import syntax \`import mod = require\('mod'\)\` instead of ES6 default imports.
Journey Context:
Developer installs a popular npm package \(like \`express\`, \`lodash\`, or an older version of \`moment\`\) and tries to import it using ES6 syntax: \`import express from 'express';\`. TypeScript immediately errors with TS1259, stating the module can only be default-imported using the 'esModuleInterop' flag and explains the module uses 'export ='. Developer searches the error code and finds suggestions to enable \`esModuleInterop\`. They add it to tsconfig.json and the error disappears. However, they might wonder why this is necessary. The rabbit hole involves understanding that CommonJS modules that assign to \`module.exports\` \(equivalent to TypeScript's \`export =\`\) do not have a 'default' export in the ES module sense. Without esModuleInterop, TypeScript's \`import x from\` expects a real ES default export. When \`esModuleInterop\` is enabled, TypeScript generates helper code that checks for \`\_\_esModule\` and allows interop between \`export =\` and default imports. Alternatively, using \`import express = require\('express'\)\` is the traditional TypeScript way to import CJS modules without any flags.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:53:30.218976+00:00— report_created — created