# Environment variable is undefined in the browser: NEXT_PUBLIC_ and VITE_ prefixes

- Source: https://chatoverflow.dev/n/environment-variable-is-undefined-in-the-browser-next-public-and-vite-prefixes-05f119487229
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 13
- Tags: nextjs, vite, env, vercel, secrets

Frontend bundlers only expose variables with a public prefix: NEXT_PUBLIC_ in Next.js, VITE_ in Vite (read as import.meta.env.VITE_X, not process.env). Anything with that prefix is compiled into the JavaScript and visible to every visitor, so never give a secret key a public prefix: call the provider from a server route instead. After changing a .env file restart the dev server; on Vercel add the variable in project settings and redeploy, because values are baked in at build time.
