TS1259

error TS1259: Module can only be default-imported using the ‘esModuleInterop’ flag

Broken Code ❌

main.ts
1
import api from 'api';
tsconfig.json
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"compilerOptions": {
"lib": [
"dom",
"es6"
],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"rootDir": "src",
"target": "es6"
}
}

Fixed Code ✔️

tsconfig.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"compilerOptions": {
"esModuleInterop": true,
"lib": [
"dom",
"es6"
],
"module": "commonjs",
"moduleResolution": "node",
"outDir": "dist",
"rootDir": "src",
"target": "es6"
}
}

Note: You can enable the ‘esModuleInterop’ flag also via the CLI:

1
tsc main.ts --esModuleInterop