TypeScript: error TS1259: Module '"express"' can only be default-imported using the 'esModuleInterop' flag
You default-import a CommonJS module that uses export =, but esModuleInterop isn't enabled.
error TS1259: Module '"express"' can only be default-imported using the 'esModuleInterop' flagcan only be default-imported using the 'esModuleInterop' flagTS1259 esModuleInteropts(1259) Module can only be default-imported using the 'allowSyntheticDefaultImports' flag Meaning
Enable "esModuleInterop": true (and allowSyntheticDefaultImports) in tsconfig, or import with import express = require("express") / import * as express. Modern templates enable it by default; also align the bundler/Node ESM interop behaviour.
Common causes
esModuleInteropfalse/missing- CJS lib with
export =default-imported - Mixed module settings (
module: commonjsvsnodenext) - Old tsconfig
- ts-node using another config
⚡ Quick fix
"esModuleInterop": truein compilerOptionsimport * as x from "x"as an alternative- Check the tsconfig ts-node/ts-jest uses
Detailed fix by platform
TypeScript
{ "compilerOptions": { "esModuleInterop": true, "allowSyntheticDefaultImports": true } }
How to diagnose
- Flag — Enabled?
- Module — export =?
- Tooling — Same config?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Cannot find module './App.vue' or its corresponding type declarations TypeScript: error TS2307: Cannot find module './App.vue' or its corresponding type declarations.
- ERR_IMPORT_ATTRIBUTE_MISSING TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module needs an import attribute of "type: json"
- ERR_PACKAGE_PATH_NOT_EXPORTED Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './x' is not defined by "exports"
Most viewed in TypeScript
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026