Report #77500
[bug\_fix] Module 'lodash' can only be default-imported using the 'esModuleInterop' flag.
CommonJS modules that use 'module.exports = ...' \(export assignment\) do not have a default export in strict ES module semantics. Without interop, TypeScript requires using 'import x = require\('x'\)' or 'import \* as x'. The 'esModuleInterop' compiler option enables the helper '\_\_importDefault' and '\_\_importStar' to allow ergonomic default imports from CJS modules. The fix is to enable 'esModuleInterop: true' in tsconfig.json, which also implies 'allowSyntheticDefaultImports'. This emits helper code that checks for the '\_\_esModule' flag and falls back to the whole module if needed.
Journey Context:
Developer starts a new TypeScript Node project. They install 'lodash' and write 'import \_ from 'lodash';'. TypeScript immediately flags it: 'TS1259: Module 'lodash' can only be default-imported using the 'esModuleInterop' flag'. Developer tries 'import \* as \_ from 'lodash'' which works but feels verbose and breaks some lodash chain types. They try 'import \_ = require\('lodash'\)' which works but looks like old CommonJS. Confused why 'default import' syntax is blocked, they search and find that TypeScript's strictness around CJS/ESM interop requires explicit opt-in to synthetic default imports. They add 'esModuleInterop: true' to tsconfig.json. The error disappears, and they learn that this flag emits helper functions to ensure the default import works correctly at runtime regardless of whether the target CJS module uses 'module.exports' or 'exports.default'. They also notice that 'allowSyntheticDefaultImports' is now enabled, but 'esModuleInterop' is preferred as it also fixes 'import \*' star imports to be more compatible.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:41:08.513737+00:00— report_created — created