Vercel: environmental variable set in panel, but not working in application
Problem: In the Vercel panel, you see an environment variable (Environment Variable), but the application returns no value or old value, or differences between build and runtime. Causes may be technical and procedural: different ranges (Environment, Preview, Production), no rebuild after change, the use of an incorrect reading mechanism (e.g. process.env in a client without NEXT PUBLAC prefix), local cache or build cache Vercel, as well as typos in variable name. Diagnosis requires separate testing of the build and runtime phase and confirmation that the variable is available in this phase and for this design/branch. Framework versions (Next.js) and build-step configurations also influence: Next.js inserts values during build into static code — changing the variable after build will not change the generated static files without re-deploya. For this reason, I propose a systematic approach: (1) check the view of the variable in the Vercel panel (Environment: Production/Preview/Development), (2) make sure that you perform deploy after each change in value, (3) verify, whether you use the correct convention (e.g. NEXT PUBLC for the values available in the browser), (4) evaluate whether the problem occurs during build or runtime — build logs and variables in server logs will help. Further steps include rebuilding a cache-cleaning project, a simple-endpoint test that returns the process.env value, and local playback of settings by vercel dev or by exporting variables to the environment It's running. In the following diagnostics, I have given options of causes, concrete steps to perform and short verification tests, which conditions eliminate potential source of error.
How to Recognize Cause
Check the Vercel Panel variable range: each variable has Environment (Development, Preview, Production). If you deploy on production, but the variable is set only for Preview, the application will not see it. In the Project → Settings panel → Environment Variables check whether the entry is in the desired view and for the right design.
Distinguish build vs runtime: frames (e.g. Next.js) settle process.env at build time for client-side code. If the variable has changed after the last build, force a new deploy. In addition, cache builda can hold an old value — use redeploy/purge cache.
Check name and availability client-side: variables used in the browser must have a framework prefix (in Next.js NEXT PUBLIC ). There is also a typo or incorrect reading (e.g. using import.meta.env in a project that does not support it).
Step by step solution
1. Verify in Vercel Panel: Projects → Settings → Environment Variables — confirm name (case-sensitive), value and Environment (Production/Preview/Development). Take a drop of the name and compare exactly what the code expects.
2 . Perform manual redeploy (Deployments → Redeploy) for the environment where the problem occurs by selecting the option 'Redefloy with Clear Cache' if available. Wait until full build logs appear and analyze them for values or messages of missing variables.
3 . Add temporary endpoint or test field in the server application that returns raw process.env['NAZWA CHANGE'] during runtime. Make sure endpoint works in the same environment as the problem and does not send value to the client if it's secret.
4 . If you use the Next.js framework and need a variable on the client side, make sure that the name starts with NEXT PUPC . Changing the name requires rebuild and redeploy; it is not enough to just edit the client code.
5 . Run locally vercel dev with the same variables (export NAME=value or use .env local) and confirm that the problem is reproduced locally. If it works locally, compare build logs and the Node/Builder version used by Vercel.
6 . Check build-step files and configurations in vercel.json (if any) — some custom builders can isolate the environment and not transmit variables to the build process. Remove custom cache or add public env to build command if needed.
7 . If everything fails, copy the variable name to a simple 'console.log(process.env.NAZWA)' script running as serverless function in Vercel and check function logs — it separates the application problem from the platform.
How to see if the problem is gone
Test 1 — log build: after redeploy check in the Deployments full log build tab. It should contain no errors such as 'undefined variable' and, if you put temporary console.log(process.env.NAZWA) in the code, it will be visible in build logs.
Test 2 — runtime function: implement a simple serverless function (api/test.js) returning process.env.NAZWA. Call endpoint after deploy and compare the returned value with the one in the panel; the difference will indicate the runtime vs build phase problem.
Test 3 — client vs server: in the client-side application, write the value value NEXT PUBLUC NAZWA to the browser console after loading the page. If undefined, check if the variable has a prefix and if the deploy was a rebuild — it will distinguish the problem of exposing from the scope.
What to do
Do not redeploy after changing values: the variables embedded in the build require full rebuild; only editing the values in the panel without redeploy will not update static artifacts.
Using secret variables on the client side without a prefix: revealing secrets to the frontend is an error; no prefix also causes the framework to not provide a variable for client-side.
The range set in the wrong environment: setting the variable only for Preview is not enough for Production — check the image compatible with the active deploy.