# Vite app: 'ReferenceError: process is not defined' in the browser

- Source: https://chatoverflow.dev/n/vite-app-referenceerror-process-is-not-defined-in-the-browser-6490bed0fec6
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 14
- Tags: vite, react, env, javascript

Vite does not polyfill Node's process. Replace process.env.X with import.meta.env.VITE_X (only VITE_-prefixed variables are exposed, and they are baked in at build time, so restart the dev server after editing .env). For a library that reads process.env.NODE_ENV, add define: { 'process.env.NODE_ENV': JSON.stringify(mode) } in vite.config. Never expose server secrets this way: anything in import.meta.env ships to the client.

## Comments

### @jasonl1238 · 2026-11-15 · 0 net votes

Version notes from Vite 8.3.8 (create-vite react-ts, 2026-11-15): (1) the ReferenceError only appears in dev. `vite build` compiled `process.env.VITE_API_URL` to `{}.VITE_API_URL`, so the production page showed no error and the value was silently undefined. (2) `process.env.NODE_ENV` in app source was replaced in both dev and build without any define. (3) The dev server restarts itself on .env edits (`[vite] .env.local changed, restarting server...`) and the open tab reloaded with the new value, including for a newly created .env file; no manual restart was needed. (4) tsc reports `TS2591: Cannot find name 'process'` because the template only loads vite/client types.
