Skip to content
Latchkey

tsc TS1259: Module can only be default-imported using esModuleInterop in CI

TS1259 fires when you import X from 'cjs-module' against a CommonJS module that has no default export, unless esModuleInterop is enabled to synthesize one. CI hits it when its tsconfig leaves interop off.

What this error means

tsc fails with "error TS1259: Module '\"x\"' can only be default-imported using the 'esModuleInterop' flag", pointing at a default import of a CommonJS package.

tsc
src/app.ts:1:8 - error TS1259: Module '"/app/node_modules/@types/express/index"' can only be
default-imported using the 'esModuleInterop' flag

1 import express from 'express';
         ~~~~~~~

Common causes

A default import of a CommonJS module without interop

CommonJS modules use export =, which has no real default export. Default-importing one requires esModuleInterop to synthesize the default.

esModuleInterop is off in the CI tsconfig

A base config or a stricter CI tsconfig omits esModuleInterop, so the default import that worked locally fails in CI.

How to fix it

Enable esModuleInterop

  1. Set esModuleInterop (which implies allowSyntheticDefaultImports) in tsconfig.
  2. Keep the same setting in any base config the CI build extends.
  3. Re-run tsc to confirm the default import resolves.
tsconfig.json
{
  "compilerOptions": { "esModuleInterop": true }
}

Use a namespace import instead

Without interop, import the whole module as a namespace, which matches the export = shape.

src/app.ts
import * as express from 'express';

How to prevent it

  • Enable esModuleInterop once and keep it consistent across configs.
  • Use namespace imports for CommonJS modules when interop is off.
  • Align local and CI tsconfig so interop behavior matches.

Frequently asked questions

What causes "TS1259 "can only be default-imported using the esModuleInterop flag""?
CommonJS modules use export =, which has no real default export. Default-importing one requires esModuleInterop to synthesize the default.
How do I fix TS1259 "can only be default-imported using the esModuleInterop flag"?
Enable esModuleInterop

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card