Open hornta opened 5 months ago
This is Vite's limitation. It allows using .js
extension for .ts
files only if the importer (index.js
in your case) is also a .ts
file. If you disagree with this decision, you can start a discussion or open an issue in the vite repository.
Hey, the biggest problem with this is that it differentiates from how typescript is handling the same situation, so code that compiles just fine cannot be tested in the same way. Which for me was a big reason to drop jest for vitest in the first place.
It sounds like I'd now have to convert every single .js
file to .ts
to make sure we're never importing a .ts
as .js
, even though this is exactly what I have to do so support NodeNext
module resolution.
If Vite does decide to keep it this way, is there anything we can do to get around it without migrating .js
to .ts
?
Unfortunate to see this not supported, but seems like it's being worked on here: https://github.com/vitejs/vite/issues/8993
Doesn't work for .svelte
files either.
Describe the bug
When I import a TypeScript file from within a JavaScript file like so
export { foo } from "./my-file.js";
(my-file is a .ts file on the FS). This should not error because TypeScript files can be imported using the JS extension.Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-ivcrw5?file=test%2Fbasic.test.ts
System Info
Used Package Manager
npm
Validations