VibeDict

🚀Environment variable is undefined in the browser

What you'll see
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

  1. Rename only the values that are safe to use in the browser to NEXT_PUBLIC_ names
  2. Never make secret keys NEXT_PUBLIC_; use them only on the server
  3. 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