-
Notifications
You must be signed in to change notification settings - Fork 407
Description
Is there an existing issue that is already proposing this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe it
tsconfig-paths is used by the nest-cli to rewrite paths according to path aliases specified in tsconfig.json.
tsconfig-paths does not work with ES Modules as reported here e.g.:
- https://stackoverflow.com/questions/71571684/ts-node-with-tsconfig-paths-wont-work-when-using-esm
- Support for ts-node + tsconfig-paths + esm jonaskello/tsconfig-paths#243
- Unable to find module with tsconfig-paths when using esm: tsconfig-paths is incompatible with native ESM TypeStrong/ts-node#1375
Thus nest start
throws an ERR_MODULE_NOT_FOUND when compiling to ES Modules and using path aliases. Here is a minimal example: https://stackblitz.com/edit/nestjs-typescript-starter-m27m4jmo
It is related to this issue: #1437. Though AFAIU the problem is not caused by the file extension. Thus I decided to open a new issue. Hope that's fine.
Describe the solution you'd like
A solution could be to use tsc-alias as a post-compilation step, instead of using tsconfig-paths in pre-compilation.
A possible benefit: Rewriting the paths with tsconfig-paths in pre-compilation involves some custom code which you could probably lose with tsc-alias.
I haven't fully tested it, but when I change the build script to "nest build && tsc-alias -p tsconfig.build.json"
, the import is correct in the compiled dist/app.module.js
after running npm run build
. See here: https://stackblitz.com/edit/nestjs-typescript-starter-rcmvukfp
Teachability, documentation, adoption, migration strategy
No response
What is the motivation / use case for changing the behavior?
We would like to use path aliases in a project and this hinders it at the moment.