BlogVariables

process.env is undefined after deploy.

A variable your code reads is undefined on the server. Five things cause almost every case, and each has a quick check.

How the Agent API works
  • What it meansThe server does not have the value
  • Check oneIs it set
  • Check twoDid you redeploy
  • Check threeIs it read at build time

The short answer

Your .env file is on your computer. The server only has the variables that were saved for it. If process.env.SOMETHING is undefined online, either it was never saved, it was saved after the app started, or it is read at build time. Ask your agent to list the variable names that are set, and compare them with the ones your code reads.

Five checks

  1. Is the variable set?

    Ask your agent: "Which environment variables are set for this app?" Your agent can list the names, never the values. If yours is not there, set it.

  2. Did you redeploy after you set it?

    The running app keeps its old values until the next deploy. A redeploy builds the last version again with the current variables, without sending the code again.

  3. Is it read at build time?

    Variables you save are available when the app runs, not while the image is being built. A value a frontend reads during the build, such as a NEXT_PUBLIC_ or VITE_ variable, is copied into the built files, so it must be set before the build. See environment variables and secrets.

  4. Is the name spelled the same?

    STRIPE_SECRET_KEY and STRIPE_SECRET are different variables. Names are case-sensitive.

  5. Does the platform already set it?

    Antideploy sets DATABASE_URL, the bucket, sign-in and email variables, your app's own address and some signing secrets for you. A copy that you set yourself wins, so a wrong copy can hide the right one.

Browser code cannot read server variables

A frontend only sees variables that its build copies in, such as NEXT_PUBLIC_ and VITE_ ones. A plain process.env.SECRET in browser code is undefined, on purpose. Never put a secret in a public variable.

01Questions

Undefined variable questions, answered.

Anything else? Write to us and a person answers.

support@antideploy.com
Why does it work locally?

Your local .env file has the value, and a tool such as dotenv loads it.

Is my .env file uploaded?

A .env in your project is read when you deploy, so you do not retype keys. The values go into the encrypted store, and the file itself is dropped from the build.

Can I read a value back to check it?

No. Values are write-only. If you doubt one, set it again.

Deploy something. Start with one sentence.

Paste one sentence into your coding agent, click Approve once, and get a live link. No card, no trial clock.

Start from GitHub or a folder
Prompt copied Paste it into Claude Code, Codex or Cursor and press Enter.