Deployment guide

Missing environment variables in production: how to find and fix them

Short answer

If your app works locally but fails after deploy, environment variables are the #1 suspect. Compare what your code references against what your host actually has defined — every difference is a potential outage.

Symptoms

  • App returns 500 errors only in production.
  • Build succeeds but pages crash with “undefined is not a function”.
  • Logs show “Cannot read property of undefined” on a config object.
  • Auth, database or AI provider calls fail silently after deploy.
  • A feature that worked yesterday is broken after a redeploy.

Common causes

  • Variable is defined in .env locally but not in the host's environment settings.
  • Variable name is misspelled or has wrong casing in one place.
  • Wrong prefix — server-only secret leaked with NEXT_PUBLIC_ or VITE_, or a public value missing the prefix.
  • Variable is set for Preview only, not Production (or vice versa).
  • Build-time vs runtime mismatch — Vite inlines at build, Node reads at runtime.

How DeployDoc checks this

  • Parses your build log for “env not found”, “undefined”, and provider-specific signals.
  • Reads the env vars referenced in your code and lists which are missing on the target host.
  • Flags client-bundled secrets (sk_*, service_role) that should never have a public prefix.
  • Detects per-environment drift (Preview vs Production) across Vercel and Netlify.

Fix it manually

  1. Open your local .env (or .env.production) and list every variable used.
  2. Grep your codebase for process.env. and import.meta.env. to catch ones not in .env.
  3. In your host dashboard, confirm each is set for the correct environment (Production / Preview / Development).
  4. For server-only secrets, remove any NEXT_PUBLIC_ / VITE_ prefix and rotate the key.
  5. Redeploy and watch the build log — most providers print “Loaded N env variables” at the start.

When to run a DeployDoc diagnosis

Run a diagnosis any time a deploy fails after working locally, or after rotating an API key. Paste the build log or drop the project zip — DeployDoc returns the exact missing names.

Related guides