-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 v5.0.2 | vite.config.js - config define | process.env variables on production not available anymore #15164
Comments
Reading the docs about how to use the esbuild define feature seemed to fix it for us:
|
Hi @pckilgore, thanks for your feedback and idea. Unfortunately it doesn't work for me. When I try to use process.env in my react code on the client side process.env just is an empty object like: console output in browser: ![]() I try to access the process.env variables like:
As I said when I start the application with I found a very interesting comment about it, but in web pack (different build approach), that basically reflects the same issue I have: |
This approach helped me and works as a workaround for me: storybookjs/storybook#17336 (comment) |
Yeah this seems to be an issue after Vite 5. This code: vite/packages/vite/src/node/plugins/define.ts Lines 65 to 67 in ef403c0
vite/packages/vite/src/node/plugins/define.ts Lines 20 to 24 in ef403c0
Is blocking I suppose we can fix this by moving |
Describe the bug
In the past I set the process.env within the vite.config.js file to can access process.env variables. I need that because I'm still using jest and need the process.env variables there as well as in cypress.
I just update to the latest version of Vite v5.0.2. I can't access the process.env variables anymore as they are empty on my production build. Locally it is still working. I think it has something to do with the changes described here.
My config looks like:
The
define: envWithProcessPrefix
still works locally for dev but not for the production build anymore. Any ideas? Thanks!Reproduction
https://stackblitz.com/edit/vitejs-vite-jujfte?file=vite.config.js
Steps to reproduce
vite build --mode dev
and then run the build locally
System Info
System: OS: macOS 14.1.1 CPU: (8) arm64 Apple M1 Pro Memory: 159.98 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.10.0 - /opt/homebrew/opt/node@20/bin/node npm: 10.2.3 - /opt/homebrew/opt/node@20/bin/npm Browsers: Chrome: 119.0.6045.159 Safari: 17.1 npmPackages: vite: ^5.0.2 => 5.0.2
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: