TS2613

error TS2613: Module ‘add‘ has no default export. Did you mean to use ‘import { add } from "add"‘ instead?

Broken Code ❌

add.ts
1
2
3
export function add(a: number, b: number): number {
return a + b;
}
main.ts
1
2
3
import add from './add';

console.log(add(1000, 337));

Fixed Code ✔️

To fix the bug we have to convert our named export into a default export:

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