What are the configs to import/export with typescript in node?

Solution 1:

See relative vs non-relative imports: in order to import from a file, you will need to start with /, ./ or ../.

Therefore you will need to update your import statement to be:

import { fun } from './test';

A relative import is resolved relative to the importing file and cannot resolve to an ambient module declaration. You should use relative imports for your own modules that are guaranteed to maintain their relative location at runtime.

Otherwise TypeScript compiler will treat it as a non-relative import and will use the NodeJS strategy to resolve it. Here's a good writeup on how TypeScript resolve modules.