Watch: Fix environment variables showing as undefined (Vite, Next.js) | Vovy

Watch Vovy do it on a Mac: "My API key shows as undefined in my app, fix my env variables". Vovy checks your variable names, prefixes and where they are read, then fixes the setup so the right values reach the right place and secrets stay secret.

"My API key shows as undefined in my app, fix my env variables"

Vovy checks your variable names, prefixes and where they are read, then fixes the setup so the right values reach the right place and secrets stay secret.

What happens in the video

  1. Find where the value is read: Vovy searches your code for the variable, like import.meta.env.VITE_API_URL or process.env.NEXT_PUBLIC_URL, and notes whether it runs in the browser or server.
  2. Check the prefix rules: Browser code only sees variables starting with VITE_ in Vite or NEXT_PUBLIC_ in Next.js. Anything else is undefined there by design.
  3. Check your .env file: It checks the file name, .env or .env.local, for typos, quotes and spaces, and restarts the dev server since values load only at startup.
  4. Flag any exposed secret: If a secret key has a public prefix, Vovy warns you that it ships to every visitor and moves the call to the server instead.
  5. Sync to Vercel and redeploy: It adds any missing names to Vercel Environment Variables and triggers a redeploy, because public values are baked in at build time.
Read the step-by-step guide