Next.js · sdk · fg-0307

NEXT_PUBLIC_ variable set at container runtime is ignored and the browser still sees the build-time value

If you see process.env.NEXT_PUBLIC_API_URL is undefined in the browser even though the container has it set, the cause and the fix for Next.js are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
process.env.NEXT_PUBLIC_API_URL is undefined in the browser even though the container has it setStaging and production images built once both call the staging APIChanging the variable in the hosting dashboard has no effect until a rebuild
Cause
next build replaces every literal process.env.NEXT_PUBLIC_* reference in client code with the value present at build time. The shipped JavaScript no longer reads the environment, so runtime values never reach it.
Fix
Pass public values as build args and rebuild per environment, or read a server-only variable in a Server Component and hand it to the client as a prop. Dynamic lookups like process.env[name] are not inlined at all.
Apply
# Dockerfile ARG NEXT_PUBLIC_API_URL ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL RUN npm run build # docker build --build-arg NEXT_PUBLIC_API_URL=https://api.example.com .
Affected
All Next.js versions with next build, most visible with one Docker image promoted across environments
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun