← All fixes
New Vercel environment variable is undefined in production
#6Error
process.env.MY_VAR is undefined on the live site even though it was added in the Vercel dashboard.
Fix
Env vars are baked in at deploy time. After adding or changing one, redeploy (vercel --prod, or Redeploy in the dashboard). Also check it was added to the Production environment, not only Preview/Development. Client-side code in Next.js only sees vars prefixed NEXT_PUBLIC_; in Vite they need the VITE_ prefix.
Did it work?
No reports yet0 worked0 didn't
Tried it yourself?
Related fixes
process.env values undefined in ESM even though dotenv.config() is called
#35process.env.API_KEY is undefined in a module, although .env has it and dotenv.config() runs at the top of the entry file
node --env-file: .env: not found
#62node: .env: not found
UnboundLocalError: cannot access local variable where it is not associated with a value
#51UnboundLocalError: cannot access local variable 'count' where it is not associated with a value (older Python: local variable 'count' referenced before assignment)
pythonVerifiedNo reports yet