# process.env is undefined after deploy.

URL: https://antideploy.com/blog/process-env-variable-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.

## At a glance

- **What it means**: The server does not have the value
- **Check one**: Is it set
- **Check two**: Did you redeploy
- **Check three**: Is it read at build time

Published 7 October 2026. Facts checked 7 October 2026. 2 min read.

## 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](https://antideploy.com/blog/how-to-set-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.

## Undefined variable questions, answered.

Anything else? Write to us and a person answers.

[support@antideploy.com](mailto: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.

## More guides, and the platform.

Each platform page covers one part of Antideploy: what it does, where it stops and the questions people ask. [See the whole platform](https://antideploy.com/platform), or [all the guides](https://antideploy.com/blog).

- [How to set environment variables and secrets](https://antideploy.com/blog/how-to-set-environment-variables-and-secrets): Encrypted and write-only. What you set, what is filled in for you, and how a change reaches the app.
- [Failed to collect page data for /api/users](https://antideploy.com/blog/nextjs-failed-to-collect-page-data): A route's code threw during the build. Usually a variable or a database call at the top of a file.
- [Why does my app work on localhost but not online?](https://antideploy.com/blog/why-does-my-app-work-on-localhost-but-not-online): Nine common reasons, how to check each one, and how to fix it.

- [Environment variables](https://antideploy.com/platform/environment-variables)
- [Deployments](https://antideploy.com/platform/deployments)
- [Agent API](https://antideploy.com/platform/agent-api)

Facts on this page were checked against the live platform on 7 October 2026.

## 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.

To set this up, give your coding agent this sentence:

```text
Set this project up to deploy on Antideploy. Fetch https://antideploy.com/agent.md and follow it.
```
