DEV Community

Discussion on: Path aliases with TypeScript in Node.js

Collapse
 
etroynov profile image
Evgeniy Troynov

You can use:
npmjs.com/package/tsconfig-paths

it much easier

Collapse
 
empflow profile image
empflow

Thank you so much! I've probably spent like 6 hours in total trying to get this to work and I finally see the listening on port 3000 log 😁

Collapse
 
itsikbelsonspotlight profile image
itsikbelson-spotlight • Edited

I also kept receiving module_not_found while running ts-node.
The way that worked for me (taken from stackoverflow.com/questions/566507...

In tsconfig.json add the following section:

"ts-node": {
      "require": ["tsconfig-paths/register"]
},
Enter fullscreen mode Exit fullscreen mode

In order to make the script run on the compiled js (for production distribution), you can defined the following script in package.json:

"scripts": {
      "start": "TS_NODE_BASEURL=./dist node -r tsconfig-paths/register dist/index.js"
}
Enter fullscreen mode Exit fullscreen mode

Don't forget to run npm i tsconfig-paths

Collapse
 
vitalodev profile image
Vital

you made my day, thx!