Typescript is transpiled to JavaScript, so a module routes.ts
is converted into routes.js
in the directory that tsc
puts it. If another module imports names (e.g., "router") from a module, we leave off the suffix as in:
import { router } from './routes'
This worked fine until node stopped using .js
as a default suffix. Starting in node V16 (or maybe earlier ?), it was necessary to add the flag
--es-module-specifier-resolution=node
in order to run the transpiled code with node.
In later nodeJS versions this option was downgraded by being silently converted into
--experimental-specifier-resolution=node
which was then dropped altogether in NodeJS v19.
Now in NodeJS v19, one is supposed to use "custom loaders" instead. Is it really that hard to run transpiled TypeScript code? What is the recommended approach?