-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Importing a TS file from a JS file with using extension .js
does not work
#11813
Comments
I think the problem is that vite use |
Is anyone aware of any workaround that can be used to fix this at the moment? Something like this works if all JS import references have an equivalent TS file. But this is not the case in my project.
|
You have 2 solutions:
|
Thank you @suguanYang! I was just reading the TypeScript 5.0 beta announcement and there's yet a new |
You could check this plugin if its support this new moduleSolution @rollup/plugin-typescript |
Duplicate of #8993 |
Describe the bug
There are a number of previous issues/PRs that have solved various aspects of this:
This and the above issues all relate to being able to import a TS file by a
.js
file extension. The previous issues seem to have solved this issue when the source file is a.ts
file or a.vue
file (with a special meta indicator). My issue is that TypeScript also supports type checking/compiling.js
files with thecheckJs
config option. In this case, I need Vite to also support looking for a.ts
file even if I provide its import path with.js
. But that is not happening right now.The problem is that I don't seem to have any easy way to satisfy both what Vite wants AND what TypeScript wants.
Please see the reproduction and steps below.
Reproduction
https://stackblitz.com/edit/vitejs-vite-6frdv6?file=package.json
Steps to reproduce
npm install
npm run tsc
npm run dev
[vite] Internal server error: Failed to resolve import "./myTsFile.js" from "main.js". Does the file exist?
main.ts
to:import { MyTsClass } from './myTsFile.ts';
(the extension is now .ts)npm run tsc
error TS2835: Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './myTsFile.js'?
npm run dev
To summarize:
tsc
wants the extension of the import to be.js
vite
wants the extension of the import to be.ts
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: