Skip to content
Latchkey

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

  1. Set esModuleInterop true (and allowSyntheticDefaultImports follows from it)
tsconfig.json
{
  "compilerOptions": { "esModuleInterop": true }
}

Use import-equals or namespace import

  1. 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

References

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