Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsconfig-paths does not work with ESM; possible switch to tsc-alias #2858

Open
1 task done
dyedwiper opened this issue Jan 6, 2025 · 0 comments
Open
1 task done
Labels

Comments

@dyedwiper
Copy link

dyedwiper commented Jan 6, 2025

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.:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant