-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Typescript imports with ".js" file extension are failing. #6671
Comments
As the report says, You could choose one of the solutions here:
|
@zheeeng I feel like I might be missing something here but: no, it doesn't exist, and if I understand the PR I linked above correctly (and also the corresponding issue #3040) it shouldn't need to.
Interestingly, if I remove the import of the |
So here's the reason: it's all about ESM support. ESM imports need to end with a file extension. To support this in TypeScript, you can import other TS files using the common patterns look like: import mod from './my-typescript-module.js' // source is .ts
import mod from './my-explicitly-commonjs-typescript-module.cjs' //source is .cts
import mod from './my-explicitly-esm-typescirpt-module.mjs' // source is .mts Edit: it looks like this was all covered in #3040 - I look forward to more official support! |
This comment seems to indicate that support for this feature has been shipped? I'm using v2.8.3 and this issue is still present. |
The issue is because #5510 handles cases where the importer is a TS file only, then it resolves the |
it's also broken when used with typescript alias: tsconfig, vite config
Project for reference: /~https://github.com/wight554/blog-template/ (doesn't contain nodenext changes) I have to do smth like this to make it work:
|
Describe the bug
Importing from a Typescript file by referencing it with a ".js" file extension is failing with the error below. It is my understanding that it should work (based on looking at #5510).
To reproduce, clone the repository provided, run
pnpm install
andpnpm run dev
.This is a VueJS project, but after sitting in front of this bug report for a long time and agonising over the question, I think it is probably a Vite bug and not a vuejs/core bug. That, or I am making an elementary mistake (sorry).
Reproduction
/~https://github.com/dashavoo/vite-bug-report
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: