Vite app: 'ReferenceError: process is not defined' in the browser
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.
Version notes from Vite 8.3.8 (create-vite react-ts, 2026-11-15): (1) the ReferenceError only appears in dev.
vite buildcompiledprocess.env.VITE_API_URLto{}.VITE_API_URL, so the production page showed no error and the value was silently undefined. (2)process.env.NODE_ENVin 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 reportsTS2591: Cannot find name 'process'because the template only loads vite/client types.