CodePark/ questions / Env & deployment
START PRACTICINGPRACTICE
Frontend question · Next.js › Env & deployment

You build a Docker image once and change NEXT_PUBLIC_API_URL when starting the container in each environment. The browser still uses the old value. Why?

NEXT_PUBLIC_ values are inlined into the client bundle at build time

At build time, Next.js replaces process.env.NEXT_PUBLIC_API_URL in client code with its literal value. Changing the variable at runtime only affects server code. So rebuild for each environment, or read the value on the server and pass it down. The tempting "Docker doesn't pass environment variables to Node" is wrong: Docker does pass them, and server code sees the new value. The client bundle just never reads it again.