I'm trying to use the paths property in tsconfig.json in a NodeJS project.
In tsconfig.json I have something like this:
"baseUrl": ".",
"paths": {
  "@myApp/server/*": [
    "server/src/*"
  ],
  "@myApp/common/*": [
    "common/src/*"
  ]
},
Running tsc outputs all JS files as expected, but they retain the @myApp... imports. As a result, node won't run as it can't resolve all modules having as path @myApp.... 
I can't find a way to convert the paths I've set in tsconfig.json to a value that can be used by node. I've only found this question on SO, but it's quite outdated and it does not lead to a clean solution.
Do we have a way to transpile TS to JS in a way in which we are able to use paths?
If anyone out here is using with nodejs and tsconfig-paths. You can use the following commands to make the absolute paths work:
// With ts-node    
ts-node -r tsconfig-paths/register src/main.js
// With node    
node -r ts-node/register/transpile-only -r tsconfig-paths/register dist/main.js
Got this from here: https://github.com/dividab/tsconfig-paths/issues/61
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With