Hi, I’m having a problem with my public environment variables (NEXT_PUBLIC_*) in my project.
Problem:
No public variable (NEXT_PUBLIC_*) is injected into the frontend in production (nor in preview), even though they are created and selected in all environments.
I tried deleting the variables and making a clean deploy with no variables, then recreating them with other names, but nothing works.
I tested with new variables (NEXT_PUBLIC_TEST, NEXT_PUBLIC_GMAPS_KEY), and those don’t work either.
No typos or spaces, and they are correctly selected for all environments (Production, Preview, Development).
Locally it works, but in Vercel always appears as “NO DEFINIDA”.
The code to display the variable value is simple:
{process.env.NEXT_PUBLIC_TEST || ‘NO DEFINIDA’}
Is there any bug, cache or internal lock in my project? How can I force Vercel to fully reset and re-inject environment variables into the frontend?
I’m sorry you are facing this issue. Did you re-deploy your project after updating the variables?
If you need more help, please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.
Hi, thanks for your reply!
Yes, I already tried all of that, but the public environment variables are still not injected into the frontend on Vercel (it always shows “NO DEFINIDA”).
I created/edited the variables (NEXT_PUBLIC_TEST, NEXT_PUBLIC_GMAPS_KEY, etc.) in the Vercel dashboard, double-checked names (no typos or spaces), and pressed “Save”.
I deleted all variables, deployed with none, then re-created them, pressed “Save” again, and did a full redeploy.
After every change, I always do a redeploy from the Vercel dashboard.
I tried new variables with different names, still not injected.
I made a test page showing {process.env.NEXT_PUBLIC_TEST || "NO DEFINIDA"} and in production (Vercel), it always shows “NO DEFINIDA” (locally it works).
My repo does not use a .env file in production—only environment variables set in Vercel’s dashboard.
Also tested in Preview and Production—same result.
Is there any other step I might be missing, or is there a bug with environment variable injection?
How is the correct/expected way to access public environment variables in Next.js 14 on Vercel (app router)?
Thanks for sharing what you tried. Can you share the link to the public repository so I can try recreating the issue? Also, a screenshot of your environment variables configuration on the project settings will be helpful for debugging.