-
Notifications
You must be signed in to change notification settings - Fork 401
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 rewrite to be broken when import with file extension (.js) #1437
Comments
Can you please provide a minimum reproduction repository? |
BTW using absolute paths (using "src" in your import paths) is considered as a bad practice |
@jmcdo29 https://github.com/HomeskilletHealthInc/nestJs_import_rewrite_bug @kamilmysliwiec Using absolute path is, but I don't believe that applies to non-relative path. The code will always compile to the same relative path, independently of the service/computer is being compiled on. Let me know if I misses something, but I haven't seen any large projects using fully relative path, nor a good argument to use them. |
Yeah just to clarify: it applies only to paths that contain |
I had the same problem and couldn't import an esm package. Do I have to change all absolute paths to relative paths. |
I am using this command temporarily |
same problem, microsoft/TypeScript#56350 |
Encountered this bug today, here's a minimum reproduction repo and steps:
"paths": {
"@/*": ["./src/*"]
}
import { AppService } from "@/app.service.js";
We can see in the compiled |
Do you have any solution for nest start @amit78523 |
Is there a way to run tsc-alias as a post build step when doing |
Is there an existing issue for this?
Current behavior
With a project organised that way:
Defining an import in
main.ts
the following way:result in it being compiled to:
ignoring the non-relative path to relative path rewrite that should be done by
tsconfig-paths
.Removing the
.js
from the import, result in the correct compilation:I took a quick look into
nest-cli/lib/compiler/hooks/tsconfig-paths.hook.ts
to see if I could spot the issues.My guess is that the match on l.56 does not return anything if the extension is set.
I'll try to ding more into it soon, but I figure I would ask in case there is an obvious fix for this.
Minimum reproduction code
https://github.com/HomeskilletHealthInc/nestJs_import_rewrite_bug
Steps to reproduce
Run:
This code:
is compiled to:
Failing to rewrite
src
when.js
is precise.Expected behavior
Defining an import in
main.ts
the following way:Should compile to:
Package version
8.1.5
NestJS version
8.2.3
Node.js version
v14.17.0
In which operating systems have you tested?
Other
The reason I would to get the
.js
is because it is required for ESMThe text was updated successfully, but these errors were encountered: