Symptom: env vars undefined after Cloudflare Pages build
Cloudflare Pages only passes variables you set in the project's settings to the build, separately for Production and Preview, and a Vite/static build bakes them in at build time. Add the variables in Workers & Pages > your project > Settings for the right environment, then trigger a new deployment.
Cause: Variables were set locally or for the wrong environment (Preview vs Production), or added after the last build.
How to fix it
- In the Cloudflare dashboard open Workers & Pages > project > Settings > Variables.
- Add each variable for Production and Preview as needed (with
VITE_prefix for Vite client vars). - Retry/redeploy: existing deployments do not pick up new values.
- Use
CF_PAGES_BRANCHetc. if build logic depends on branch.
In Supabase apps this symptom often surfaces as Error: supabaseUrl is required. in the browser console.
Example
Illustrative example, not from a customer project.
# Pages > Settings > Variables (Production)
+ VITE_SUPABASE_URL = https://xyz.supabase.co
+ VITE_SUPABASE_ANON_KEY = <public anon key>
FAQ
I added the variable; why is it still undefined?
The value is read at build time. Trigger a new deployment.
Preview works but production doesn't.
Production and Preview have separate variable sets.
QUICK FIX · $49 · THIS ERROR ONLY
Get this exact error fixed — $49 Quick FixFixed within scope, or we keep working until it is · Read-only access Not sure it's this error? $149 diagnosis
- Fixed, or we keep working free until it is (within the written scope).
- A human reviews every fix before it ships.
- Read-only access; fixes arrive as pull requests you merge.
- Your $149 diagnosis is credited in full toward any paid job.
One error, one root cause, fixed in your app. If it turns out bigger, we tell you before doing more, and your $49 is credited toward the fix, diagnosis or Launch Path if you book within 14 days. Fixing three? The 3-Error Pack is $119.
Bigger job: Getting the whole app live? Launch Path, $1,195 flat.
Built with Lovable, Bolt, Replit, Cursor or v0? See rescue by platform and the security checklist.