TS2614
TS2614: Module './add.js'has no exported member
add. Did you mean to useimport add from "./add.js"instead?
Broken Code ❌
add.ts
export default function add(a: number, b: number): number {
return a + b;
}main.ts
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:
import add from './add.js';An alternative solution would be using a named export:
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:
export default function add(a: number, b: number): number {
return a + b;
}
export { add };