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.
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
- Set
esModuleInterop(which impliesallowSyntheticDefaultImports) in tsconfig. - Keep the same setting in any base config the CI build extends.
- Re-run tsc to confirm the default import resolves.
{
"compilerOptions": { "esModuleInterop": true }
}Use a namespace import instead
Without interop, import the whole module as a namespace, which matches the export = shape.
import * as express from 'express';How to prevent it
- Enable
esModuleInteroponce 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.