🚀Environment variable is undefined in the browser
console.log(process.env.API_URL) → undefined
An environment variable that shows up on the server is empty in browser code. It's blocked on purpose, for security.
🤔 Why does it happen?
- In Next.js, the name must start with NEXT_PUBLIC_ to be visible in the browser (VITE_ for Vite)
- The value was added, but the site wasn't rebuilt and redeployed
🔧 Try this
- Rename only the values that are safe to use in the browser to NEXT_PUBLIC_ names
- Never make secret keys NEXT_PUBLIC_; use them only on the server
- Deploy again after the change
🤖 Ask your AI like this
An environment variable comes out as undefined in my browser code. Please first decide whether this value is safe to expose in the browser, then rename it properly or change the code to use it on the server.
Replace the [ ] parts with your own situation, and paste the error with a few extra lines before and after it.
Related terms
Other errors in this group
- Build failed (deploy failed)
Build failed - Missing environment variable
Missing environment variable - Wrong API key
Invalid API key - Timed out (504 Timeout)
504 Gateway Timeout - Domain not found (DNS)
DNS_PROBE_FINISHED_NXDOMAIN - Secure connection error (SSL certificate)
Your connection is not private - Deployed site shows 404 (Vercel NOT_FOUND)
404: NOT_FOUND (Vercel) - Server function failed to run (FUNCTION_INVOCATION_FAILED)
500: FUNCTION_INVOCATION_FAILED - Only a white screen after deploying
배포했더니 흰 화면만 나와요