Skip to content
>_VibeUnstuck

ENVIRONMENT_NOT_FOUND on Vercel

Last verified:

The fix

ENVIRONMENT_NOT_FOUND means that name is not a Vercel environment, so the variables never shipped. Use production, preview, or development, then redeploy.

  1. 1

    Match the name to an environment that exists

    Run vercel env ls or open Project, Settings, Environments. Use production, preview, or development, or a custom slug that is actually in that list. If the CLI says Invalid environment: or the body says ENVIRONMENT_NOT_FOUND, fix the name. Do not create a second project to hold the variable.

  2. 2

    Put the variable on Production, then redeploy

    A variable checked only for Development is what .env.local received. Production will not see it. Enable Production (and Preview, if previews need it), save, and redeploy. The deployment that already finished keeps the old set. A build that throws Environment variable not found before this point is the other Vercel page.

  3. 3

    Remove the localhost fallback

    If the server reads the variable with a fallback, production will not crash when the value is absent. Drop the fallback and fail that request with a clear 500 when the variable is missing. Do not commit .env.local to make Production match your laptop.

    const databaseUrl = process.env.DATABASE_URL;
    if (!databaseUrl) {
      throw new Error("DATABASE_URL is missing");
    }
  4. 4

    Do not publish the secret to get it into the bundle

    NEXT_PUBLIC_ values are inlined at build time and are visible in the browser. A server secret stays unprefixed. Adding the public prefix so the client "can see production" ships the secret. Rebuild after a public value changes. Saving it does not rewrite the deployment that already built.

Why it happens

Vercel CLI 65 rejects vercel env add and vercel env pull with Invalid environment: <name>. Valid environments: production, preview, development, and then any custom environment slugs that exist on that project. prod and staging are not built-in names. A custom environment counts only while it is still listed. If the response body contains the code ENVIRONMENT_NOT_FOUND, it is the same miss: the environment name is not on this project.

That is a different failure from a build log that says the variable is missing. There the environment exists, and the variable was never saved on it. A third version does not throw. vercel env pull writes Development values into .env.local. Production does not read that file. Code that does process.env.DATABASE_URL || "localhost" deploys cleanly and then calls localhost.

The next error you'll probably hit

Once this is fixed, the usual follow-up is Environment variable not found on Vercel. Environment variable not found on Vercel: .env.local stayed on your machine. Add the variable for Production, then redeploy. Do not commit that file.

Prompt to paste back into your AI tool

Paste this above the error.

Vercel reports ENVIRONMENT_NOT_FOUND, or the CLI prints Invalid environment: <name>. Valid environments include production, preview, and development.

The variable we expected in production is <NAME>. It works locally via .env.local.

Do not commit .env.local. Do not prefix a secret with NEXT_PUBLIC_. Do not default the variable to localhost, an empty string, or a hardcoded URL. Do not create a new Vercel project to hold the variable.

1. Say whether the environment name is invalid, or the name is valid and the variable is only set for Development.
2. If the name is invalid, tell me the exact flag to use (production, preview, development, or a custom slug that vercel env ls shows). Do not invent staging.
3. If Production is unchecked, tell me to enable it and redeploy. Say that the current deployment will not pick the value up.
4. If the code uses a fallback, remove it and throw when the server variable is missing. Show only that read.

Common questions

+I ran vercel env pull and production is still empty. Why?

Pull writes the Development environment into .env.local unless you asked for another target. That file is gitignored and is not the Production deployment. Set the variable for Production and redeploy.

+The build is green and the app still calls localhost. Why?

The code falls back when the variable is missing, so the build has nothing to throw. Remove the fallback. Production was never given the variable, or this deployment was built before you added it.

Related errors