TS1259: Module can only be default-imported using esModuleInterop - in CI
A CommonJS module with an export-assignment is default-imported, which TypeScript allows only with esModuleInterop.
What this error means
Type-checking fails with TS1259 telling you to enable esModuleInterop for a default import.
tsc
src/server.ts(1,8): error TS1259: Module '"express"' can only be default-imported using the 'esModuleInterop' flag.Common causes
How to fix it
Enable esModuleInterop
- Set esModuleInterop true (and allowSyntheticDefaultImports follows from it)
tsconfig.json
{
"compilerOptions": { "esModuleInterop": true }
}Use import-equals or namespace import
- Without interop, use import express = require("express") or import * as express
ts
import * as express from 'express'How to prevent it
- Enable esModuleInterop project-wide so CommonJS default imports work consistently.
Frequently asked questions
What causes "TS1259 esModuleInterop flag"?
Type-checking fails with TS1259 telling you to enable esModuleInterop for a default import.
How do I fix TS1259 esModuleInterop flag?
Enable esModuleInterop
Related guides
TS1192: Module has no default export - in CIFix "error TS1192: Module 'x' has no default export" when tsc runs in CI - a default import of a module that…
TS2349: This expression is not callable - in CIFix "error TS2349: This expression is not callable" when tsc runs in CI - calling a value whose type has no c…
TS1208: isolatedModules - file cannot be compiled - in CIFix "error TS1208: ... cannot be compiled under '--isolatedModules' because it is considered a global script…