-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Add path alias to nest new #13294
Comments
I'm personally against using path aliases within a single application project. Typescript supports it for the sake of libraries, and Nest integrates with |
The goal is not to have it by default, instead, opt-in without the hassle of doing and breaking the project. |
By having it as an option, in my opinion, we would be encouraging bad development practices, which I don't believe fall inline with the desires of the framework. I'll let @kamilmysliwiec have the final say, but that's my two cents |
Why would this be a bad development practice? See, when you create a new NestJS project today, on app.e2e-spec.ts we get the following import statement: With path alias, this would become something like: Much cleaner. |
but now you're kinda mixing testing config with app config. But yeah, it's cleaner for sure To me, ideally, we need a tsconfig file for |
Again, Typescript allows for aliases for the sake of libraries. Typescript's golden rule is to not change the import statements during compilation (save for import to require for CJS). Nest makes this work by integrating Also, your first import statement has an extra |
For the way NestJS organizes it's folders, maybe 2 aliases would be better, one for src and another for test. The tsconfig.json would become like: {
"compilerOptions": {
// other options
"paths": {
"@/*": ["src/*"],
"#/*": ["test/*"],
}
}
} As a consequence, a ts file created under test folder could have it's import statement like |
that's even worse to me because, unlike Next.js, nestjs doesn't need to tell us on how our path aliases should look like. Perhaps we just need to make a recipe in the docs site on how to use path aliases |
A recipe would be a good fit, I think |
This is a TypeScript compiler's feature. I don't see a reason why we should be duplicating docs and creating a recipe on something that Nest didn't introduce in the first place #13294 (comment) couldn't agree more |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
I have an issue when I try to setup path alias, sometimes causing basic modules not to be found
Describe the solution you'd like
Adding a possibility to configure path alias in the CLI, similar to create-next-app
Teachability, documentation, adoption, migration strategy
When creating a new project, ask for the possibility to use import alias.
What is the motivation / use case for changing the behavior?
Avoid using long relative paths on import statements.
The text was updated successfully, but these errors were encountered: