Lovable
deployment
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
Cannot read property of undefined
Supabase URL is undefined
API key is required
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 Help