ReferenceError: process is not defined
- Vite
- React
What it means
The code uses process.env, which exists on servers but not in the browser. Vite apps read settings with import.meta.env, and only variables starting with VITE_ are available there.
Why it happens
- Code copied from a Node or Next.js example uses process.env.
- The variable has no VITE_ prefix, so it is not passed to the browser.
How to fix it
- Read browser settings with import.meta.env.VITE_SOMETHING.
- Only add the VITE_ prefix to values that are safe for anyone to see.
- Secret keys belong on a server or edge function, never behind VITE_.
Let your AI find the cause
Paste this into Claude Code, Cursor, Lovable or whichever AI built your app. It looks first and changes nothing until you have read the answer.
My Vite app fails with 'process is not defined'. Without changing anything yet, find every process.env in browser code, and for each value tell me whether it is safe to be public (VITE_) or must move to a server.