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.
Get a $149 diagnosis See pricing Launching soon? The Launch Path gets you ready for $1,195 flat.
- 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.