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
Cannot read property of undefinedSupabase URL is undefinedAPI key is required

Common Causes

  1. Environment variable doesn't have VITE_ prefix
  2. .env file not loaded during build
  3. Using process.env instead of import.meta.env
  4. Environment variables not set in production deployment platform
  5. 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=xxx

Access in code:

import.meta.env.VITE_SUPABASE_URL

Set same variables in production platform (Vercel, Netlify, Railway env settings).

Real developers can help you.

Jared Hasson Jared Hasson Full time lead founding dev at a cyber security saas startup, with 10 yoe and a bachelor's in CS. Building & debugging software products is what I've spent my time on for forever Matthew Butler Matthew Butler Systems Development Engineer @ Amazon Web Services Krishna Sai Kuncha Krishna Sai Kuncha Experienced Professional Full stack Developer with 8+ years of experience across react, python, js, ts, golang and react-native. Developed inhouse websearch tooling for AI before websearch was solved : ) Rudra Bhikadiya Rudra Bhikadiya I build and fix web apps across Next.js, Node.js, and DBs. Comfortable jumping into messy code, broken APIs, and mysterious bugs. If your project works in theory but not in reality, I help close that gap. Sage Fulcher Sage Fulcher Hey I'm Sage! Im a Boston area software engineer who grew up in South Florida. Ive worked at a ton of cool places like a telehealth kidney care startup that took part in a billion dollar merger (Cricket health/Interwell health), a boutique design agency where I got to work on a ton of exciting startups including a photography education app, a collegiate Esports league and more (Philosophie), a data analytics as a service startup in Cambridge (MA) as well as at Phillips and MIT Lincoln Lab where I designed and developed novel network security visualizations and analytics. I've been writing code and furiously devoted to using computers to make people’s lives easier for about 17 years. My degree is in making computers make pretty lights and sounds. Outside of work I love hip hop, the Celtics, professional wrestling, magic the gathering, photography, drumming, and guitars (both making and playing them) Anthony Akpan Anthony Akpan Developer with 8 years of experience building softwares fro startups Pratik Pratik SWE with 15+ years of experience building and maintaining web apps and extensive BE infrastructure Mehdi Ben Haddou Mehdi Ben Haddou - Founder of Chessigma (1M+ users) & many small projects - ex Founding Engineer @Uplane (YC F25) - ex Software Engineer @Amazon and @Booking.com rayush33 rayush33 JavaScript (React.js, React Native, Node.js) Developer with demonstrated industry experience of 4+ years, actively looking for opportunities to hone my skills as well as help small-scale business owners with solutions to technical problems Daniel Vázquez Daniel Vázquez Software Engineer with over 10 years of experience on Startups, Government, big tech industry & consulting.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help

Frequently 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.

Related Lovable Issues

Can't fix it yourself?
Real developers can help.

You don't need to be technical. Just describe what's wrong and a verified developer will handle the rest.

Get Help