-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Vite 5.4.0 env var fails when bundling Vite-bundled library #17874
Comments
On top of the discussions at #17648, I think it may be easiest to increment the variable name if the existing one is already used. Performance might be affected a bit, but not every module would access env vars so it's probably fine. Another solution might be to give a different variable name when building in library mode, but that would still cause problems if the Vite library bundles an internal Vite library too. |
I think that we could use a virtual module like |
I don't think we need to go that far to resolve this naming issue. Doing an |
I've created #17876 to fix this. |
Also encountered this issue.
|
Describe the bug
This was brought up at #17648 (comment)
When a library uses Vite (library mode) to bundle and uses env var, the
const __vite_import_meta_env__ = {
may get included in the code. When that happens and we bundle that library in our app, we re-inject the variable declaration again here, which causes a runtime error:vite/packages/vite/src/node/plugins/define.ts
Lines 139 to 148 in fcf50c2
Reproduction
silverwind/vite-import-meta#1
Steps to reproduce
No response
System Info
Used Package Manager
npm
Logs
Click to expand
Validations
The text was updated successfully, but these errors were encountered: