-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 Compileroption to add Extensions to relative imports #47436
Conversation
also #16577 |
With this compiler option, valid typescript, could emit valid javascript for the browser. Otherwise the imports in browser are invalid. |
@RyanCavanaugh |
and one more question: |
at the 👍 people here, would it be a solution if i create a typescript fork, where this is possible? |
There is limited support via #13764. For more general plugin support there is #16607.
That sounds like a great job for a linter. |
Please log a suggestion for this (one might exist already; please search)
This has complexity pretty far beyond where we could reasonably expect an external contributor to do this |
I add the changes of this pull as a diff, cause maybe I'll delete it at some time from my Repo...
|
I now dig a little bit deeper in the Typescript Sourcecode. TypeScript/src/compiler/transformer.ts Line 41 in c71ff4d
there are custom transformers already... and now I found this project... https://github.com/dropbox/ts-transform-import-path-rewrite/tree/main/examples/ttypescript so my whole approach is already possible without a change to typescript. so the extension point already exists. And I could convert my TS change to external transformer (I think it should work). I will test, and this maybe could be the solution for most of the people wich had this issue |
@RyanCavanaugh |
It's really annoying to add |
I am both surprised and disappointed that a clear flawed design (bug) can just continue to exist and PR's to fix it are being rejected by seemingly one stubborn TS team member. The fact that #40878 has overwhelming support in favour of fixing this should be an indicator that something is wrong. Scripts like this: https://gist.github.com/silassare/cc3db860edeea07298cb03f64738c997#file-fix-esm-import-paths-js should not be necessary in 2023, let alone 2020 when #40878 was opened. TypeScript and ES are supposed to bring the ecosystem forwards. |
Still hoping the TS team reconsider on this one. I understand the argument about not altering JS behavior, but adding file extensions (behind a flag, disabled by default) doesn't feel like a meaningful semantic change and would create huge value for developers! Or at least add some clear documentation about how one should use Typescript to output ESM code that 'just works' with Node |
Hi @RyanCavanaugh, After reading all the issues and related comments about this (including this one of yours), I wonder: Wouldn't everyone be happy if we allowed using I mean, if the problem is not transforming perfectly valid JS code, then Example:
The problem with |
Just woking with the |
Please see this comment re: extension rewriting. |
Good evening everyone, how about giving ts-add-js-extension a try? Unlike most tools that use regex to manipulate text, or act as a About this tool Pros
Cons
(Heck, it can also run on JavaScript project if developers are lazy to specify the file extension) Try it, it should be very helpful as it quite comprehensive. Appreciate any feedback |
@GervinFung Thanks for the link buddy, and for the package, it worked great. This is my preferred solution as I also do not want my source files referencing build artifacts, where the use of .js extensions on imports breaks Jest tests. |
Fixes #47188, #40878, #15479, #13422, #16577