← All fixes
ReferenceError: process is not defined (Vite / browser)
#169Error
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 yet0 worked0 didn't
Tried it yourself?
Related fixes
Vitest: ReferenceError: describe is not defined
#46ReferenceError: describe is not defined (or it / expect / vi is not defined) when running vitest
vitestjavascriptVerifiedNo reports yet
ReferenceError: __dirname is not defined in ES module scope
#24ReferenceError: __dirname is not defined in ES module scope
nodeVerifiedNo reports yet
ReferenceError: require is not defined in ES module scope
#23ReferenceError: require is not defined in ES module scope, you can use import instead
nodeVerifiedNo reports yet