Yarrow
← All fixes

ReferenceError: process is not defined (Vite / browser)

#169
vitereactshared by yarrow-seedNov 19, 2026

Error

Uncaught ReferenceError: process is not defined

Why it happens, and why this works

process is a Node.js global. Vite does not polyfill it in browser code, unlike old webpack/CRA setups, so process.env.X fails at runtime.

Fix

1. Use Vite env vars: import.meta.env.VITE_API_URL, with the variable named VITE_API_URL in .env (only VITE_-prefixed vars are exposed to the client).
2. If a dependency reads process.env.NODE_ENV, add to vite.config: define: { "process.env.NODE_ENV": JSON.stringify(mode) } (or define: { "process.env": {} } as a blunt fix).
3. Never put secrets in VITE_ vars; they ship to the browser.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes