typescript
modules
ai_generated
true
error TS1259: Module can only be default-imported using the 'esModuleInterop' flag
ID: typescript/ts1259-can-only-default-import-esinterop
97%Fix Rate
98%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5 | active | — | — | — |
Root Cause
Trying to default-import a CommonJS module without esModuleInterop enabled.
genericWorkarounds
-
97% success Enable esModuleInterop in tsconfig.json: 'esModuleInterop': true
Allows default imports from CJS modules; recommended by TypeScript team
Sources: https://www.typescriptlang.org/tsconfig#esModuleInterop
-
85% success Also enable allowSyntheticDefaultImports if esModuleInterop is not feasible
Less strict; only changes type checking, not emit behavior
Dead Ends
Common approaches that don't work:
-
Using require() instead of import
70% fail
Bypasses TypeScript module checking; loses type information
-
Using import * as X from 'module'
55% fail
Works but makes all usage look like X.default; awkward API
Error Chain
Frequently confused with: