DEV Community

Discussion on: Tired Of Relative Imports? Time To Get Rid Of Them!

Collapse
 
valeriavg profile image
Valeria

While this method does work everywhere for TypeScript, it won't work for JavaScript without a bundler (especially NodeJS).
For NodeJS one could use NODE_PATH=./src node index.js to achieve similar results.

Collapse
 
adamcoster profile image
Adam Coster

This doesn't work for the JavaScript compiled by Typescript either, since the Typescript compiler doesn't rewrite import paths on compile. I ended up switching to Babel with the "Module Resolver" plugin for my Node projects (instead of using tsc) since being able to use path aliases is worth the annoyance of the extra dependency!

Collapse
 
christian102094 profile image
Christian Tapia

Spent several hours trying to configure it for Typescript. A real nightmare!

Thread Thread
 
valeriavg profile image
Valeria

Did you figure in the end? Otherwise try tsconfig-paths

Thread Thread
 
patarapolw profile image
Pacharapol Withayasakpunt

Can also be done with Babel, JavaScript also.

Collapse
 
iamludal profile image
Ludal πŸš€

Thanks! I'm always using it with React, so I didn't think about this point. πŸ™

Collapse
 
heyprotagonist profile image
Anguram Shanmugam

now this post is perfectπŸ‘

Some comments have been hidden by the post's author - find out more