Doesn't work. Created a simple example with absolute imports and then compiled it via tsc. On running node dist/index.js the compiled JS throws an error as the absolute paths are not resolved.
After transpiling this to JS, it doesn't work just by calling node dist/index.js, where dist is the output folder. So the baseUrl is just for TypeScript as Node doesn't understand that.
But wouldn't Node complain after we transpile TS, as Node doesn't know about absolute paths?
tsc will automatically resolve it.
ts-node and ts-node-dev currently won't, but can be fixed with
-r tsconfig-paths/register
.Doesn't work. Created a simple example with absolute imports and then compiled it via
tsc
. On runningnode dist/index.js
the compiled JS throws an error as the absolute paths are not resolved.Let's see your example buddy?
It can be fixed via babel-plugin-module-resolver, though. Actually, Babel can do much more than tsc, and typescript can run under it as well.
Only just it doesn't help with the IDE.
I have two files:
src/index.ts
src/utils/math.ts
My tsconfig.json - the rest is omitted
After transpiling this to JS, it doesn't work just by calling
node dist/index.js
, where dist is the output folder. So thebaseUrl
is just for TypeScript as Node doesn't understand that.Now I really need to compile to JavaScript as you mentioned.
I summed up the solution, but not exactly that pretty.
TypeScript, simplified import paths, and what you have to be careful
Pacharapol Withayasakpunt ・ Jul 23 ・ 2 min read