-
-
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
import.meta doesn't work with esbuild since 0.5.17 #503
Comments
The warning is saying that esbuild is configured with ES2019 as the target instead of ES2020. The import.meta syntax is an ES2020 feature, so it's transformed when the target is ES2019 to avoid causing a syntax error in browsers that don't support it. It looks like the esbuild target for Vite was lowered to ES2019 because at the time Rollup didn't support optional chaining (an ES2020 feature): #155. However, I believe Rollup has since added support for optional chaining: rollup/rollup#3582. So perhaps the ES2019 target is no longer necessary? Raising the target to ES2020 should fix this issue. |
You are right. I haven't notice that Vite is setting explicitly ES2019 in the plugin. Thought it is loaded from tsconfig.json, so it is definitely Vite's issue. If vite is not planning to change it to ES2020 or ESNext, can we please at least have option to set the target from vite.config? |
When you upgrade your yarn.lock by
yarn upgrade
, the esbuild is upgraded to latest version:0.5.19
.That introduces a bug where you are not anymore able to use
import.meta
.The object
import.meta
is empty, even when .env is set and loaded properly.My solution was to find
esbuild
inyarn.lock
and replace it for older version:When developer uses the latest:
He will start getting warnings:
Even when
tsconfig.json
doesn't exist ormodule
andtarget
are set toESNext
.It must be related to this issue: evanw/esbuild#208
Is there any way how to support import.meta from esbuild?
it took me few hours to find why the import.meta is not working, so I believe opening this issue will help other developers to find this issue too.
The text was updated successfully, but these errors were encountered: