You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Next.js should not parse server environment variables during build but during runtime.
Currently environment variables inside the next.config.js get parsed during the build, which is a problem if you use next in docker for multiple environments. Usually this is dealt with by building a docker Image specifically for each environment, where the env-vars of the environment are provided and "baked in". I would rather build an environment agnostic Docker Image. This also specifically only applies to the next.config.js, every other environment variable gets parsed during runtime as expected.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Goals
Next.js should not parse server environment variables during build but during runtime.
Currently environment variables inside the next.config.js get parsed during the build, which is a problem if you use next in docker for multiple environments. Usually this is dealt with by building a docker Image specifically for each environment, where the env-vars of the environment are provided and "baked in". I would rather build an environment agnostic Docker Image. This also specifically only applies to the next.config.js, every other environment variable gets parsed during runtime as expected.
Non-Goals
No response
Background
I have built a workaround, where i replace the env vars during build with placeholders and replace them again on startup of the docker image. You can find the repo with the example here: https://github.com/AnsgarH1/nextjs-demo-no-env-vars-in-config-when-standalone/tree/main
Also there was a discussion about this about three years ago, which lead to nothing: #21888
Proposal
Don't parse the server-environment variables inside the next.js config during build
Beta Was this translation helpful? Give feedback.
All reactions