Cloudflare Pages troubleshooting

Fix Cloudflare Pages Environment Variables Not Working

Environment variables can be build-time, runtime, or framework-prefixed. Verify where the variable is read and whether your framework requires a public prefix.

Common symptoms

  • The build succeeds but API calls fail in production.
  • process.env.MY_KEY is undefined after deploy.
  • A frontend variable works locally but is missing in Cloudflare Pages.

What to check first

Platform: Cloudflare Pages
Error: Environment variables are undefined

Environment variables can be build-time, runtime, or framework-prefixed. Verify where the variable is read and whether your framework requires a public prefix.

Step-by-step fix

  1. Add variables under Cloudflare Pages ? Settings ? Environment variables for Production and Preview as needed.
  2. Redeploy after adding variables because build-time variables are baked into the output.
  3. For frontend-exposed variables, use the prefix required by your framework, such as VITE_ for Vite or NEXT_PUBLIC_ for browser-side Next.js values.
  4. Keep private secrets server-side only; do not expose API secrets through public prefixes.
# Vite browser variable
VITE_API_URL=https://api.example.com

# Next.js browser variable
NEXT_PUBLIC_SITE_URL=https://example.com

Common mistake to avoid

Do not put private API keys in public frontend variables. Public prefixes expose values to the browser.

Still stuck?

Send the deploy log, repository link, target platform, and expected URL. ShipFast Deploy Rescue is a fixed-price debugging service for indie projects and MVPs.