Fixes › Env vars & leaked keys
Environment variable is undefined in production
The error
process.env.X is undefined / import.meta.env.VITE_X is undefined after deploy
Why it happens
Your .env file is not uploaded when you deploy. Variables must be added in the hosting dashboard (Vercel, Netlify), and client-side values need the framework prefix (NEXT_PUBLIC_ for Next.js, VITE_ for Vite). Values are embedded at build time, so you must redeploy after adding them.
How to fix it
- Add the variable in Vercel → Project → Settings → Environment Variables for Production (and Preview).
- Use the right prefix for values the browser needs; keep secrets unprefixed and server-only.
- Redeploy, since env changes apply only to new builds.
- Log on the server whether the variable exists (never log its value).
Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)
Environment variable <NAME> works locally but is undefined in production on Vercel. Check whether it's read in client or server code, rename it with NEXT_PUBLIC_/VITE_ only if it is safe to be public, otherwise move the usage to server code. List the exact variables I must add in the Vercel dashboard and remind me to redeploy.
FAQ
Why does it work locally?
Your local dev server reads .env; the deployed build doesn't have that file.
Do I need to redeploy?
Yes. Env vars are injected at build/deploy time.
Related fixes
- Supabase service_role key exposed in frontend code
- OpenAI / Stripe secret key leaked in the browser
- OpenAI 429 'You exceeded your current quota' or a surprise AI bill
- .env file committed to GitHub
Want the full checklist for this area? Get a Fix Kit ($29)
Featured slot available: reach thousands of vibe coders. Sponsor this week →
Get one new fix a week
Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.
We only use your email to send the newsletter. Unsubscribe any time. See privacy.