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
Absolute import paths cannot be used in production #74
Comments
Is this actually a supported way of running NestJS? If it is, in addition to production it also does not appear to work in tests. |
If it isn't supported we should remove |
Also remove |
You should never use such absolute imports |
Is there any way tsconfig paths can be enabled without baseUrl? Or can we at least warn new users of the side effects. Because |
@dantman Unfortunately, no. I have been struggling with the same issue as well and this is actually unbearable in the long run. I hope that IDEs will provide better integration with TS options soon. |
@kamilmysliwiec Since you're having this issue to (in vscode I presume), could you try setting |
Thanks @dantman. However, I believe that it will disable |
@kamilmysliwiec Can you confirm if that is the case, I don't have any typescript-paths to test. If it is then I'll try to get the other bug reopened. |
try create a index.js in root path
then, node -r tsconfig-paths/register index.js |
The problem is that we don't have This is the reason why imports like There are several solutions:
PS: I prefer the third solution. Warning: Previously proposed solution is a bad solution!
Because this is the same to Notes: |
@korniychuk Thank you so much! Third solution is awesome. |
The third solution can be improved.
To do this we need to write a simple script for The full solution you can find in this fork of the original starter: |
I've finally got it working without having to specify multiple aliases, and it works in production, here are the steps for my future self:
Done! Basically the idea here is that with Now we can import with absolute paths, for example with |
@microcipcip Thanks! You just saved my ass XD. |
This one worked for me perfectly. |
VSCode is making absolute imports (src/...) during autoimport, which breaks teh watch. The imports should be relative as compilation goes into ./dist. BaseUrl is required if using paths, but since that's not currently being used, easiest solution is to comment out baseurl. If paths will be used, then an alternative should be chosen. See nestjs/typescript-starter#74 for more information.
With baseUrl set to "./", vscode autocompletes import path as absolute. It's a bad practice, see nestjs/typescript-starter#74 for more info. Moreover, using absolute path conflicts with module resolution in jest.
With baseUrl set to "./", vscode autocompletes import path as absolute. It's a bad practice, see nestjs/typescript-starter#74 for more info. Moreover, using absolute path conflicts with module resolution in jest.
@microcipcip |
If for some projects works it may be that they have solved it with a slightly different configuration like point 2.0 of this answer. |
Issue
Absolute import paths like
import { foo } from 'src/utils/foo'
work great withts-node
, but fail when runningnpm run start:prod
.Error
Here is a fork of
typescript-starter
with minimal changes to reproduce the issue. Compare changes.The
start:prod
command is already changed to include thetsconfig-paths/register
module, fromto
unfortunately without any effect.
The text was updated successfully, but these errors were encountered: