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.
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!
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.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!
Spent several hours trying to configure it for Typescript. A real nightmare!
Did you figure in the end? Otherwise try
tsconfig-paths
Can also be done with Babel, JavaScript also.
Thanks! I'm always using it with React, so I didn't think about this point. π
now this post is perfectπ