TS2306

File 'add.ts' is not a module.

Broken Code ❌

add.ts
function add(a: number, b: number): number {
  return a + b;
}
main.ts
import { add } from './add';
 
console.log(add(1000, 337));

Fixed Code ✔️

The error TS2306 signals that the file (add.ts) can be found (otherwise it would throw error TS2307) but does not provide the necessary exports. We can solve this with a named export:

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

Alternatively, we can use a default export:

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

Using a default export requires that we also adjust our import statement in main.ts (otherwise we would end up with error TS2614):

main.ts
import add from './add';
 
console.log(add(1000, 337));

Video Tutorial