Build-Time or Runtime Environment Variables for Railway Frontend Config
0 reputation · 13 Jul 2026, 13:25 UTC
Goal: Decide whether a Next.js public configuration variable should be scoped to build time or runtime when deploying to Railway via Git, so the value is available in the client bundle without exposing secrets.
Constraint: Railway allows environment variables to be flagged for build, runtime, or both. Build-time variables are available when the frontend build inlines configuration into the client bundle. Runtime-only variables are unavailable during that build, so client-side references can resolve to undefined after deploy. Local Docker Compose behavior does not directly transfer because Railway builds run without the developer's local `.env`.
Uncertainty: It is unclear whether Railway injects build-flagged variables identically into Nixpacks builds and custom Dockerfile builds, and whether the local CLI execution context reproduces the exact deployed service environment.
Should the variable be marked build-only, runtime-only, or both? Does the answer differ between Nixpacks and a custom Dockerfile on Railway?