Menu

Do NEXT_PUBLIC values change at startup? Run one Next.js build with two environments
📰

Do NEXT_PUBLIC values change at startup? Run one Next.js build with two environments

DEV Community: nextjs·hiro@·8 days ago
#2qbMctsp
#devtonextjs#devto#dev#server#build
Reading 0:00
15s threshold

Changing a NEXT_PUBLIC_ value and restarting the server left this browser display at its build-time value. A dynamically rendered Server Component, however, read the server-only value supplied at startup.

With process.env , the time at which a value is determined matters. One Next.js 16.3.4 build was started under two different environments.

Give build and startup different values

Every value is a synthetic string that is safe to display:

Phase ARTICLE_SERVER_LABEL NEXT_PUBLIC_ARTICLE_LABEL

Build server-build-A public-build-A

Startup B server-runtime-B public-runtime-B

Startup C server-runtime-C public-runtime-C

B was stopped before starting C, with no rebuild between them. Their BUILD_ID values matched. This is not a test of .env precedence; values were passed explicitly to the processes.

The environment-variable documentation describes inlining directly referenced public values during the build and freezing them afterward.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.