Skip to content

Vercel deploymentVercel environment variable is undefined in production

Everything works on your machine, then the deployed app fails because a key or URL is undefined. On Vercel this is usually one of three settings. Here’s each in Vercel’s own words, and the fix, or hand it over at a fixed price.

Short answer

Vercel applies a new or changed variable only to new deployments, so redeploy (a new build) after saving it. Check it’s enabled for the right environment, Production or Preview. And if the browser needs it, it must use your framework’s public prefix, such as NEXT_PUBLIC_ in Next.js, which also means it’s visible to anyone, so never put secrets there.

Why it’s undefined, and the fix

  1. 01

    Saved, but not redeployed

    “Any change you make to environment variables are not applied to previous deployments, they only apply to new deployments.” Vercel, Environment variables

    Adding or editing a variable doesn’t change the deployment that’s already live. Redeploy, or push a commit, and check the new deployment.

  2. 02

    Set for the wrong environment

    “When selected, the Environment Variable will be applied to your next Production Deployment.” Vercel, Environment variables

    Each variable is enabled for Production, Preview, Development or a mix. A variable set only for Preview is missing on your live domain, and the other way round. Branch-specific Preview values also override the general ones.

  3. 03

    Needed in the browser without the public prefix

    “Frameworks typically use a prefix to expose environment variables to the browser.” Vercel, Framework environment variables

    Code that runs in the browser only sees variables named with your framework’s prefix, such as NEXT_PUBLIC_ in Next.js or VITE_ in Vite. Add the prefix only for values that are safe to publish, because the browser gets them.

Checked against the vendor’s docs on : Vercel docs: Environment variables; Vercel docs: Framework environment variables.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Vercel function timeout (504) · Build failed on Netlify or Vercel · Supabase service_role key exposed

Questions

More on this error

Should I add the prefix so it just works?

Only for values meant to be public, like a Supabase anon key or a site URL. A secret key with a public prefix ends up in the JavaScript anyone can read, so keep secrets server-side.

It works in preview but not on my domain. Why?

Preview and Production have separate values. Check the variable is enabled for Production, then redeploy production.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.