Next.js + Vercel troubleshooting

Fix Next.js Environment Variables Not Working on Vercel

Next.js variables behave differently on the server and browser. Private variables stay server-side, while browser variables require NEXT_PUBLIC_ and a redeploy.

Common symptoms

  • process.env works locally but is undefined in Vercel.
  • A browser-side value is missing after deploy.
  • The app still uses an old value after changing the Vercel setting.

What to check first

Platform: Next.js + Vercel
Error: Environment variables are missing on Vercel

Next.js variables behave differently on the server and browser. Private variables stay server-side, while browser variables require NEXT_PUBLIC_ and a redeploy.

Step-by-step fix

  1. Add the variable in Vercel Project Settings ? Environment Variables for the correct environment.
  2. Use NEXT_PUBLIC_ only for values that are safe to expose in browser JavaScript.
  3. Redeploy after changing env vars because build-time values are not updated in old deployments.
  4. If using server actions, route handlers, or API routes, keep secrets without NEXT_PUBLIC_.
# Server-only secret
DATABASE_URL=postgres://...

# Browser-visible value
NEXT_PUBLIC_APP_URL=https://example.com

Common mistake to avoid

Do not expose database URLs, payment secrets, or private API keys with NEXT_PUBLIC_.

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.