ReferenceError: process is not defined
Last verified:
The fix
process is not defined in Vite, including Lovable and Bolt: browser code read process.env. Use import.meta.env.VITE_NAME and restart the dev server.
- 1
Read import.meta.env, with the VITE_ prefix
Replace
process.env.NEXT_PUBLIC_...orprocess.env.SOMETHINGin client code withimport.meta.env.VITE_SOMETHING. Restart the dev server after any.envchange. Vite loads env files at startup, and the env guide says to restart after you edit them.const url = import.meta.env.VITE_SUPABASE_URL; if (!url) { throw new Error("VITE_SUPABASE_URL is missing"); } - 2
Keep secrets off the VITE_ prefix
A
VITE_value is public. The Supabase URL and the publishable key are public. A service role key, a Stripe secret, or an OpenAI key is not. Call those from a server you control. Do not rename a secret toVITE_so the reference error goes away. - 3
Do not define process.env as the whole environment
Do not add
define: { 'process.env': process.env }to silence the error. Vite stringifies non-string define values, which drops every variable from the environment into the bundle. If one public value has to be injected, the config docs show a single key:'import.meta.env.ENV_VARIABLE': JSON.stringify(process.env.ENV_VARIABLE). Do not setenvPrefixto''. - 4
Check the built file if this only fails in production
A dev server can hide a bad env read that the production bundle still contains. Search the built JavaScript for
process.envand for the secret's prefix. Fix the source, restart, and build again. The previous bundle keeps the old inlined value.
Why it happens
Vite bundles client code for the browser. The browser has no Node process global, so process.env.SOMETHING throws ReferenceError: process is not defined as soon as that line runs. Vite's env guide says client code reads import.meta.env, and that only variables prefixed with VITE_ are exposed. An unprefixed name is undefined there on purpose. The values are strings, and they are written into the bundle at build time. The same guide says VITE_ variables must not contain secrets such as API keys.
process.env in vite.config is the Node process that is running Vite, which is a different place. A define entry of 'process.env': process.env is a common patch for this error. Vite's config docs say a non-string define value is passed through JSON.stringify, so that one line can embed the whole environment object in the client bundle. Setting envPrefix to an empty string is also rejected, because it would expose every variable.
The next error you'll probably hit
Once this is fixed, the usual follow-up is supabaseUrl is required. supabaseUrl is required: createClient got an empty URL or key, missing when the bundle was built. Set the Supabase URL and anon key, then rebuild.
Prompt to paste back into your AI tool
Paste this above the error.
A Vite app throws ReferenceError: process is not defined. The line uses process.env in browser code.
Do not set define to { 'process.env': process.env }. That can stringify every env var into the client bundle. Do not set envPrefix to an empty string. Do not put a secret in a VITE_ or NEXT_PUBLIC_ variable. Do not disable RLS. Do not swallow this in an empty catch.
1. Find the process.env read in client code and switch it to import.meta.env.VITE_NAME.
2. If the value is a secret, move the call to a server and remove it from the client. Say so instead of adding the VITE_ prefix.
3. Tell me to restart the dev server after the .env change.
4. Touch only that read and the env name.Common questions
+I copied a Next.js example into a Vite app. Why did process.env break?
Next.js replaces process.env.NEXT_PUBLIC_* in its client bundle. Vite does not provide a process global in the browser. The Vite name is import.meta.env.VITE_*.
+import.meta.env.VITE_NAME is undefined after I added it to .env. Why?
The dev server was not restarted, the name does not start with VITE_, or the variable was added after the production bundle was built. Restart, then build again for production.
Related errors
- supabaseUrl is requiredsupabaseUrl is required: createClient got an empty URL or key, missing when the bundle was built. Set the Supabase URL and anon key, then rebuild.CursorLovableBoltSupabaseNext.jsOct 19, 2026
- process.env.NEXT_PUBLIC_ is undefinedprocess.env.NEXT_PUBLIC_ is undefined. The name is missing from .env.local, it has no NEXT_PUBLIC_ prefix, or Next.js has not been restarted since you added it. Do not put a secret on that prefix.CursorLovableBoltNext.jsVercelNov 3, 2026
- NEXT_PUBLIC_ secret in the bundleA NEXT_PUBLIC_ or VITE_ secret is in the browser bundle. Rotate the key, move the call to a server route, and keep real public keys in the client.CursorLovableBoltNext.jsViteNov 11, 2026
- Lovable export code won't run: bun installLovable export code won't run until you install with the lockfile in the folder. bun.lock means bun install, then the dev script. Do not add Next.js.LovableCursorViteNodeNov 2, 2026
- Failed to start dev server in BoltFailed to start dev server in Bolt means the Vite preview crashed before paint. Read the first red line in the terminal, fix that error, and restart.BoltCursorViteReactOct 14, 2026