-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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.env.DEV
and PROD
are incorrect if a custom mode
is provided programmatically
#9203
Comments
I think this is expected behaviour per the docs. You'd need to set |
We have the same issue here. The NODE_ENV=production doesn't set |
@cedeber can you provide a repro for that? Using the repro in this issue, adding |
Unfortunately no. But I think I've found the change (not sure it's an issue though). If I move the |
I'll go ahead and close this since I agree with @bluwy that it's working as intended |
Hang on a sec @benmccann — it's not working as intended. Either |
The docs are a bit ambiguous, I think: A lot hinges on the interpretation of 'running in production'. If it means 'running in If instead 'production' means 'the output of I'd argue that since the observed behaviour depends entirely on whether |
Here's the logic as implemented, which looks at a few different variables to figure out if it's production: vite/packages/vite/src/node/config.ts Line 450 in 60721ac
|
I'm not sure it should reflect But it does sounds like there's a bug here if passing the |
Wow, it was not clear for me that I believe the |
That's a valid position, but it's often very useful to know if you're in import.meta.env.COMMAND; // 'build' or 'serve' |
So |
And according to https://vitejs.dev/guide/env-and-mode.html#modes:
It further explains that So I think this isn't a bug. Maybe we could improve the docs, or implement a good fallback as proposed (which I think make sense, but for Vite 4), but it is still working as intended. |
Thanks for the illuminating discussion. The only way I'm able to get Assuming the logic mentioned above: vite/packages/vite/src/node/config.ts Lines 450 to 452 in 60721ac
I tried running my code in production mode using
Is it safe to say that configuring production mode is only possible with |
Yes, you can't set vite/packages/vite/src/node/config.ts Lines 363 to 365 in 1983cf4
I agree that we could probably mention this somewhere in the docs. |
Discussion here: #9274 |
I believe this is fixed in #10996. Vite build will always default to prod by default, unless specifically changed with |
Describe the bug
Ordinarily, building a Vite app results in
import.meta.env.DEV === false
andimport.meta.env.PROD === true
regardless of themode
configuration.If you set
mode
when callingvite.build(...)
programmatically, however,DEV
andPROD
aretrue
andfalse
unless themode
happens to beproduction
.Reproduction
https://github.com/Rich-Harris/vite-mode-repro
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: