Next.js · sdk · fg-0307
NEXT_PUBLIC_ variable set at container runtime is ignored and the browser still sees the build-time value
process.env.NEXT_PUBLIC_API_URL is undefined in the browser even though the container has it set
Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100
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 .
Affects: All Next.js versions with next build, most visible with one Docker image promoted across environments
Sources
- https://nextjs.org/docs/app/guides/environment-variables
- https://github.com/vercel/next.js/issues/53367
Have your agent know this before it fails
claude mcp add --transport http footgun https://getfootgun.com/api/mcp