-
-
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
[2.5.0-beta] Cannot import typescript types if importsNotUsedAsValues is not "remove" #4581
Comments
I think it's a bug in esbuild. |
Reported the problem upstream evanw/esbuild#1525 |
There is a response in related esbuild issue:
So, how the current issue can be solved right now for vite? It adds some pain to the current dev experience |
For now I've separated out my type imports from value imports. Honestly, I think it's cleaner and definitely more explicit that way anyway. But I agree it's not ideal to force devs to do that. |
Another workaround is to set importsNotUsedAsValues to "remove" |
I wanted to evaluate Vite for https://github.com/cubing/cubing.js/ and it mostly worked like a charm, except for this. My VSCode tooling mixes type imports with value imports by default, and Vite's interpretation of
This is very helpful to know, thanks! I'd love for Vite to match TypeScript semantics for (This thread suggests that it requires a fix in |
Yes, this change seems to have been introduced in #4279 |
See vitejs/vite#4581 And evanw/esbuild#1525 This lead to npm run watch not working when upgrading svelte kit which in turn updated vite to 2.5
Version 0.14 of ESBuild contains a change in behavior with regards to this setting. The behavior of Therefore I think this issue can be closed. |
@dummdidumm can be closed with vite 2.8 release with #5861 merged |
Closing as #5861 is merged |
Describe the bug
The title is a little misleading, you cannot
import
types, but you canimport type
.After #4279 began respecting tsconfig settings, I began getting errors from
import
statements which mixed value and types. I've narrowed it down to only happening whenimportsNotUsedAsValues
is set topreserve
orerror
.So, for example, this has started to fail in my app:
As a workaround, I can change it to:
But I think I should be able to mix them, right?
Note, this only happens in dev mode. Running
yarn build && yarn serve
does not throw an error in the console. Which makes me think this might be an esbuild bug, perhaps?Reproduction
https://github.com/IanVS/vite/tree/ts-type-import
Clone my fork, checkout the
ts-type-import
branch,yarn
,yarn build-vite
,cd packages/playground/ts-import
,yarn dev
, and see the error in the browser console:System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: