TS1259: Module can only be default-imported using the 'esModuleInterop' flag (TypeScript) — how to fix
error TS1259: Module '"/app/node_modules/@types/express/index"' can only be default-imported using the 'esModuleInterop' flag
1 import express from "express";
~~~~~~~
node_modules/@types/express/index.d.ts:133:1
133 export = e;
~~~~~~~~~~~
This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
Quick fix: Add "esModuleInterop": true to compilerOptions in tsconfig.json (it also enables allowSyntheticDefaultImports). Or, without changing config, use import express = require("express") or import * as express from "express". Make sure the tsconfig you edit is the one actually used.
What it means
Many CommonJS packages (express, react types before v19, lodash, moment, cors...) are typed with export = something. Strictly, such a module has no default export, so import express from "express" is not valid unless TypeScript is told to synthesize one.
esModuleInterop does two things:
- Type-checking: allows default imports of
export =modules (viaallowSyntheticDefaultImports). - Emit: adds
__importDefault/__importStarhelpers so the import works at runtime in CommonJS output.
Fix 1: enable esModuleInterop (recommended)
{
"compilerOptions": {
"esModuleInterop": true
}
}
This is the default in tsc --init configs and what most projects use. Restart your editor's TS server afterwards (VS Code: TypeScript: Restart TS Server).
If a bundler (Vite, webpack, esbuild) emits the JS and tsc only type-checks, "allowSyntheticDefaultImports": true is enough. It's also implied by "module": "system", "moduleResolution": "bundler" and "esModuleInterop": true.
Fix 2: use import syntax that matches export =
Without changing config:
import express = require("express"); // works with module: commonjs
const app = express();
or a namespace import, for modules you don't call directly:
import * as path from "path";
Note: import * as express from "express"; express() type-checks only without esModuleInterop, and calling a namespace object is invalid in real ESM. Prefer Fix 1.
Fix 3: the setting is in the wrong tsconfig
You set the flag, but the error remains:
- Monorepos and frameworks use several configs (
tsconfig.app.json,tsconfig.node.json,tsconfig.build.json). Check which one includes the failing file. extendsis overridden by a latercompilerOptionsvalue.- Running
tsc file.tswith a file name ignores tsconfig.json entirely. Runtsc -p .ornpx tsc --noEmit. - ts-node / Jest may use their own config; pass it explicitly (
ts-jestreadstsconfigoption).
Print the effective config:
npx tsc --showConfig | grep -i interop
Fix 4: check @types and the module setting
"module": "node16", "nodenext" and "preserve" turn esModuleInterop on by default, so the error normally disappears with those settings. If it persists, an explicit "esModuleInterop": false somewhere in the extends chain may be overriding it, or outdated type packages may be involved — update them (npm i -D @types/express@latest).
Runtime symptom of the same problem
If you silence the type error some other way (e.g. // @ts-ignore) without esModuleInterop, compiled CommonJS code calls express_1.default(), which crashes with TypeError: (0 , express_1.default) is not a function. Enabling esModuleInterop fixes both.
Last updated 2026-11-13.