Two kinds of variable
| Prefix | Visibility |
|---|---|
| (no prefix) | Server-only. Read at runtime. Never reaches the browser. |
NEXT_PUBLIC_ | Inlined into the client bundle at build time. Visible in DevTools. |
The build-time gotcha
NEXT_PUBLIC_* values are baked in when you run next build. Re-deploying the same Docker image to staging and prod gives you the same values; you can't change them by setting an env var on the running container.
Loading order
process.env(already-set values win).env.production.local/.env.development.local.env.local(skipped in test).env.production/.env.development.env