TS2614

TS2614: Module './add.js' has no exported member add. Did you mean to use import add from "./add.js" instead?

Broken Code ❌

add.ts

1
2
3
export default function add(a: number, b: number): number {
return a + b;
}

main.ts

1
import {add} from "./add.js";

Fixed Code ✔️

There are multiple ways to fix this. The simplest would be turning your import statement into a default import:

1
import add from "./add.js";

An alternative solution would be using a named export:

1
2
3
export function add(a: number, b: number): number {
return a + b;
}

You could actually use a named export and a default export in the same file:

1
2
3
4
5
6
7
export default function add(a: number, b: number): number {
return a + b;
}

export {
add
};