VercelDeployEnv vars

Vercel build fails: environment variable not found

error: Environment variable not found: DATABASE_URL.

In short: The host ran a production build without a variable your code (or Prisma, or an env schema) reads at build time. Adding it only for runtime is not enough.

Why it happens

A Vercel build runs next build (or your install/build commands) in an environment that only has the variables you added in the project settings, for that environment (Production vs Preview). .env.local never leaves your machine. Values needed while the build prerenders pages, runs prisma generate, or validates an env schema must be present during that build, then you have to redeploy so a new build can see them. This is different from a deploy that succeeds and then fails at runtime because a server-only variable is missing.

How to fix it

  1. Compare every name in .env.local with Vercel → Project → Settings → Environment Variables, including the NEXT_PUBLIC_ or VITE_ prefix if you use one.
  2. Tick the environments that should see it (Production, Preview, Development). After you add or edit a variable, trigger a new deployment; an already-finished build will not pick up the change.
  3. If the log says Environment variable not found: DATABASE_URL (Prisma) or an env schema fails during install/build, the variable must be available at build time, not only at runtime. A placeholder connection string is enough for prisma generate if the build never connects to the database.
  4. If the log says Failed to collect page data or Error occurred prerendering page, a module is reading the variable while Next.js generates a static page. Either add the variable to the build, or stop importing that client at the top of a page that is statically rendered.
  5. Confirm in the build log that the name is present. You can print Boolean(process.env.DATABASE_URL) (never the value) from a build-time script if you need to check.
Don't: Don't commit a real .env file to the repo to make the build pass, and don't print secret values in build logs.

Copy-paste fix prompt

3 · The fix promptPaste into Cursor, Claude Code, Codex, Lovable, Bolt, Replit or v0
I'm getting this error in my app:

error: Environment variable not found: DATABASE_URL.

[Paste the full error, stack trace, and the file it points to here]

Likely cause: The host ran a production build without a variable your code (or Prisma, or an env schema) reads at build time. Adding it only for runtime is not enough.

Task: List every environment variable the production build reads (including Prisma and any env schema), check each one is set in Vercel for the right environment and available at build time, and tell me which ones to add. Don't print secret values.

Rules:
- First explain the root cause in 2 sentences and list the files you'll change.
- Make the smallest change that fixes it. Don't refactor unrelated code.
- Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear.
- Never print or hard-code secret keys.
- Finish by telling me exactly how to verify the fix.

Common with: Cursor, v0, Claude Code, Bolt. Last reviewed 2026-11-15.

Related fixes

← All fixes · Still stuck? Use the diagnose-first prompt