Environment Variables Undefined in Production Build
API keys and configuration values are undefined in production. Supabase URL and API key return undefined, causing all API calls to fail. Works locally with .env.local but not in production.
Vite only exposes variables prefixed with VITE_ to the client. Production requires proper build-time or runtime environment setup.
Error Messages You Might See
Common Causes
- Environment variable doesn't have VITE_ prefix
- .env file not loaded during build
- Using process.env instead of import.meta.env
- Environment variables not set in production deployment platform
- Build cache not cleared after env change
How to Fix It
Use VITE_ prefix for client-side variables in .env:
VITE_SUPABASE_URL=https://xxx.supabase.co
VITE_SUPABASE_KEY=xxxAccess in code:
import.meta.env.VITE_SUPABASE_URLSet same variables in production platform (Vercel, Netlify, Railway env settings).
Real developers can help you.
You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.
Get HelpFrequently Asked Questions
How do I expose env variables to browser?
Use VITE_ prefix in .env file. Access with import.meta.env.VITE_VARIABLE_NAME
How do I set env in production?
Use deployment platform's environment variable settings (Vercel, Netlify dashboards) or set in hosting environment.