Why is my environment variable undefined in the browser on a Next.js/Vercel deploy? #51
Answered
by
Kevinchamplin
Kevinchamplin
asked this question in
Q&A
-
|
Why is my environment variable undefined in the browser on a Next.js/Vercel deploy? |
Beta Was this translation helpful? Give feedback.
Answered by
Kevinchamplin
Jun 13, 2026
Replies: 1 comment
-
|
Next.js only exposes env vars to client-side code if they're prefixed with NEXT_PUBLIC_; anything else is server-only and reads as undefined in the browser by design (so you don't leak secrets). Also, env vars are inlined at build time on Vercel — after adding or changing one you have to trigger a new deploy for it to take effect. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kevinchamplin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Next.js only exposes env vars to client-side code if they're prefixed with NEXT_PUBLIC_; anything else is server-only and reads as undefined in the browser by design (so you don't leak secrets). Also, env vars are inlined at build time on Vercel — after adding or changing one you have to trigger a new deploy for it to take effect.