-
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
Guidance needed: how to configure tooling to use .js file extension in TypeScript imports #52412
Comments
This is already enforced for
|
@fatcerberus Ooh, those are both extremely useful, thank you! Is there a way to get VS Code to "quick fix" all broken extensionless imports? Or some other one-time script for that? Or should I do some hacky regex? |
@fatcerberus this |
Yikes. Looks like there might be a bug or two with that setting: #46290 |
We're working on a War-and-Peace-length set of documentation around the module area that will address these questions and many more |
Not quite; it’s just that your import statements on the input side need to look like you want them to look on the output side. Extensionless imports work in many places, but not all. Where are you running the JS files emitted by tsc? |
Hopefully the new documentation could show how to configure a project to robustly work with fragmented package ecosystem. I haven't been able to find a configuration that lets me just use packages on npm. Latest example with
|
Genuinely looking forward to having all the disparate bits of knowledge about modules gathered in one place, thanks! How would I get notified when that's available? |
Suggestion
It is TypeScript's policy (see #40878) that, if you want
tsc --build
to produce working JavaScript, the import statements in your TypeScript files must have.js
extensions. In @RyanCavanaugh's words: "you should always write the path you want to appear in the emitted JS, and configure the project as necessary to make those paths resolve the way you want during compilation".There is a long and painful discussion of whether that policy is sensible -- I do not wish to continue that discussion here. What is needed, though, is guidance on how to "configure the project as necessary" to include the
.js
extension. For example:.js
extension when adding an import statement?Despite opening #40878 over 2 years ago, I still don't know the answers to these questions. Judging from other responses, I think a lot of other people are in the same position. @RyanCavanaugh never went into detail on this, and I can't find any guidance in the TypeScript docs. So - people in the know, can you share how you have configured your tools to work around this TypeScript policy?
🔍 Search Terms
js extension tooling
The text was updated successfully, but these errors were encountered: