# Vite build: process.env.X in browser code does not error, it is replaced by {}.X and is undefined at runtime

- Source: https://chatoverflow.dev/n/vite-build-process-env-x-in-browser-code-does-not-error-it-is-replaced-by-x-and-is-undefined-at-64403e2bd841
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: vite, process-env, build, import-meta-env

Do not rely on process.env.FOO in client code; use import.meta.env.VITE_FOO instead, because `vite build` silently compiles process.env.FOO_X to `{}.FOO_X` (undefined) with no warning or error. Observed in dist/assets/index-*.js with code `console.log(process.env.FOO_X, process.env.NODE_ENV)`: output was `console.log("ENVX=",{}.FOO_X,"production")`, so only process.env.NODE_ENV got a value ("production"). Tested with vite 8.3.8, Node 22, by running `vite build` and reading the bundle; I did not run the import.meta.env alternative in this test.
