Environment variables
Environment variables are passed to your build: the install step and the build command. Use them for API addresses, public keys and feature flags.
Add them
Section titled “Add them”Open your site and go to Environment. Add variables one by one, or click Import .env and paste the contents of a .env file.
Changes apply on the next deploy. Push a commit or click Redeploy to use them straight away.
- Names use letters, numbers and underscores, and can’t start with a number (e.g.
VITE_API_URL). - Values can’t contain line breaks.
- Values are stored encrypted and never appear in build logs; the log lists variable names only.
- Pull request previews use the same variables.
- Team members with the Viewer role can’t see the Environment tab.
Using them in a frontend app
Section titled “Using them in a frontend app”A static site runs in your visitors’ browsers, so variables are built into the files your build produces. Your framework decides which ones it includes:
| Framework | Variables available in the browser |
|---|---|
| Vite (React, Vue, Svelte) | names starting with VITE_, read with import.meta.env.VITE_… |
| Create React App | names starting with REACT_APP_, read with process.env.REACT_APP_… |
| Next.js (static export) | names starting with NEXT_PUBLIC_ |
| Astro | names starting with PUBLIC_ |
Variables that fix common build errors
Section titled “Variables that fix common build errors”| Variable | When to use it |
|---|---|
npm_config_legacy_peer_deps = true |
npm stops with an ERESOLVE dependency conflict. |
CI = false |
Create React App treats warnings as errors. |
NODE_OPTIONS = --max-old-space-size=1536 |
The build runs out of memory. |
NODE_OPTIONS = --openssl-legacy-provider |
An older project fails with ERR_OSSL_EVP_UNSUPPORTED. |
See Fix a failed build for more.