Environment variable not found on Vercel
Last verified:
The fix
Environment variable not found on Vercel: .env.local stayed on your machine. Add the variable for Production, then redeploy. Do not commit that file.
- 1
Add the variable in the Vercel project
Project, Settings, Environment Variables. Add the name and value for Production, Preview, and Development as you actually need them. Preview builds do not see Production-only variables.
- 2
Redeploy
Saving a variable does not rebuild the failed deployment. Deploy again. Confirm the new deployment’s build log, not the old one.
- 3
Do not commit .env.local
Keep secrets out of git. Commit
.env.examplewith the names and empty values so the next person knows what the build expects. - 4
Separate build-time from request-time
If a secret is only needed when a user hits an API route, read it inside the handler and return a clear 500 if it is missing. Avoid throwing at the top of a module that Next imports while it prerenders pages.
NEXT_PUBLIC_variables still have to exist at build time, because they are baked into the client bundle.
Why it happens
.env.local is gitignored. Vercel builds from the repo and from the environment variables you set in the project, not from your laptop.
A variable set only for Production is absent on Preview deployments. A variable added in the dashboard does not change the deployment that already failed. You have to redeploy.
NEXT_PUBLIC_ values are inlined while next build runs. A server secret referenced at module scope can also throw during the build if the code checks it as soon as the file is imported, including during page data collection.
The next error you'll probably hit
Once this is fixed, the usual follow-up is supabaseUrl is required. supabaseUrl is required: createClient got an empty URL or key, missing when the bundle was built. Set the Supabase URL and anon key, then rebuild.
Prompt to paste back into your AI tool
Paste this above the error.
The Vercel build fails because an environment variable is missing. It works locally via .env.local. Do not commit .env.local. Do not prefix a secret with NEXT_PUBLIC_ so the build can see it. 1. Name the exact variable the build reads, and whether it is server-only or NEXT_PUBLIC_. 2. If it is only needed inside a route handler, move the read into that handler so a missing value fails the request instead of the whole build. 3. List the Vercel environments (Production, Preview, Development) where it must be set. Tell me to redeploy after adding it. 4. Do not rewrite unrelated files.
Common questions
+I added the variable and the same deployment still failed. Why?
That deployment already ran. Environment changes apply to the next build. Redeploy.
+Why does Production work and the pull-request preview fail?
The variable is scoped to Production only. Edit it and enable Preview, then redeploy the preview.
Related errors
- supabaseUrl is requiredsupabaseUrl is required: createClient got an empty URL or key, missing when the bundle was built. Set the Supabase URL and anon key, then rebuild.CursorLovableBoltSupabaseNext.jsOct 19, 2026
- process.env.NEXT_PUBLIC_ is undefinedprocess.env.NEXT_PUBLIC_ is undefined. The name is missing from .env.local, it has no NEXT_PUBLIC_ prefix, or Next.js has not been restarted since you added it. Do not put a secret on that prefix.CursorLovableBoltNext.jsVercelNov 3, 2026
- NEXT_PUBLIC_ secret in the bundleA NEXT_PUBLIC_ or VITE_ secret is in the browser bundle. Rotate the key, move the call to a server route, and keep real public keys in the client.CursorLovableBoltNext.jsViteNov 11, 2026
- ENVIRONMENT_NOT_FOUND on VercelENVIRONMENT_NOT_FOUND means that name is not a Vercel environment, so the variables never shipped. Use production, preview, or development, then redeploy.Cursorv0BoltVercelNext.jsOct 20, 2026
- Treating warnings as errors because process.env.CI = trueThe Vercel build log says Create React App is failing on warnings because CI is true. A Next.js log that says Failed to compile with a type error is a different check.Cursorv0BoltVercelReactOct 27, 2026