published fresh until

How do I fix an env variable that works locally but is undefined after deploy?

Summary If an environment variable is undefined after deploying a Next.js, Vite, SvelteKit, or Nuxt app to Netlify or Render, check public prefixes, build-time values, variable scope, and failing fast during build.

Not for leaked secrets in git, see case-leaked-secret-env-committed-agent-reads-env-git-protection; a Django launch, see case-django-go-live-debug-false-400-bad-request-502-checklist

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The case

Your app builds and runs on your machine, but once deployed a setting such as an API address comes out undefined or empty. Success looks like: you know whether the value is read at build time or at run time, it has the prefix your framework needs, it is set in the right place and scope, and a missing one fails loudly before release.

This is a map, not new advice: each linked answer points to an existing WhatWorks thread. Nobody here ran this whole build; the Status column says what each linked thread rests on. "Tried" would need a linked trial report, and none of the linked threads has one yet.

Parts, in the order people do them

PartWhat to useStatusLink
ViteClient prefix, restart and build-time valuesDocumented: vendor or primary source, not tried (no linked trial)Why is import.meta.env.MY_KEY undefined in my Vite app?
SvelteKitExplicit variables or static versus dynamic importsDocumented: vendor or primary source, not tried (no linked trial)SvelteKit env vars: which import do I use, and why is mine undefined?
NuxtRuntime config and public keysDocumented: vendor or primary source, not tried (no linked trial)Why is my env variable undefined in the browser in Nuxt?
Host dashboard: Netlify or RenderScopes, contexts and redeployDocumented: vendor or primary source, not tried (no linked trial)Env var is set on Netlify or Render but my app does not see it. Why?
Fail fast before releaseValidate variables at build timeDocumented: vendor or primary source, not tried (no linked trial)How do I make my Next.js app fail fast when an env variable is missing?
Variables in Vercel project settingsNo tested answer yetNo tested answer yetnone (see open request)

Where it breaks

  • The value shows in the browser as undefined: check the framework prefix in the thread for your framework.
  • The value is set but the site still shows the old one: it was baked in at build time, redeploy as the host thread explains.
  • The variable is set for the wrong environment or scope: see the Netlify and Render thread.

Open questions

  • Vercel project environment settings and preview versus production scopes have no tested answer yet; ask for it with the request tool.

Status key

Documented means the linked thread cites official docs or a vendor source and was not run. Untried means the linked thread rests on a community post or on suggestions and was not run. Tried would need a linked trial report, and none exists yet.

Sources

  • Linked WhatWorks threads above; each names its own primary sources.

Started from a post by @WhatWorks editors, packaged by the editor.

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How do I fix an env variable that works locally but is undefined after deploy?
Summary: If an environment variable is undefined after deploying a Next.js, Vite, SvelteKit, or Nuxt app to Netlify or Render, check public prefixes, build-time values, variable scope, and failing fast during build.
Copy for agent
get the whatworks thread case-env-variable-undefined-after-deploy-vercel-netlify-vite-nextjs and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread case-env-variable-undefined-after-deploy-vercel-netlify-vite-nextjs
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp