Report #16356
[bug\_fix] TS1259: Module 'lodash' can only be default-imported using the 'esModuleInterop' flag OR TS2349: This expression is not callable with 'import \* as lodash'
Enable 'esModuleInterop': true \(and optionally 'allowSyntheticDefaultImports': true\) in tsconfig.json, then use 'import lodash from 'lodash''. Root cause: CommonJS modules that export a single entity via 'module.exports = ...' are not technically ES modules with a 'default' export. Without interop, TypeScript treats 'import \* as' as creating a namespace object lacking call signatures. 'esModuleInterop' enables a set of helper functions that allow these legacy CommonJS modules to be imported as if they were ES modules with default exports, handling the 'default' property extraction automatically.
Journey Context:
You install 'lodash' in a TypeScript project and write 'import \_ from 'lodash';'. The IDE immediately underlines it with 'TS1259: Module 'lodash' can only be default-imported using the 'esModuleInterop' flag'. You change it to 'import \* as \_ from 'lodash';' which satisfies the compiler. However, when you run the code, you get 'TypeError: \_ is not a function' when calling '\_.chunk\(array, 2\)'. You inspect the compiled JS and see it calls 'lodash\_1.default.chunk', but the actual lodash module doesn't export a 'default' property in the same way. You search GitHub issues and find that TypeScript's module interop is the issue. You add 'esModuleInterop': true to tsconfig.json. You revert the import to 'import \_ from 'lodash''. Now the emitted JavaScript contains helper code that checks for '\_\_esModule' and correctly accesses 'module.exports' when the imported module is CommonJS. The code now runs without runtime errors. You understand that this flag effectively tells TypeScript to treat the import as a standard ES module default import while generating runtime logic to handle the legacy CommonJS format.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:25:27.258528+00:00— report_created — created