using process.env.SOMETHING next.config.js is in build time?
Unanswered
Prairie Falcon posted this in #help-forum
Prairie FalconOP
I am trying to understand if, for example, when using process.env.API_URL in rewrite rule in next.config.js is compiled in build time? I am setting different API_URL environment variable and it doesn't change.
4 Replies
American Fuzzy Lop
Yes, it's baked in at build time, not runtime
Prairie FalconOP
Anywhere in next docs that it is documented?
American Fuzzy Lop
https://nextjs.org/docs/pages/building-your-application/configuring/environment-variables
"Note: After being built, your app will no longer respond to changes to these environment variables. For instance, if you use a Heroku pipeline to promote slugs built in one environment to another environment, or if you build and deploy a single Docker image to multiple environments, all NEXTPUBLIC variables will be frozen with the value evaluated at build time, so these values need to be set appropriately when the project is built. If you need access to runtime environment values, you'll have to setup your own API to provide them to the client (either on demand or during initialization)"
"Note: After being built, your app will no longer respond to changes to these environment variables. For instance, if you use a Heroku pipeline to promote slugs built in one environment to another environment, or if you build and deploy a single Docker image to multiple environments, all NEXTPUBLIC variables will be frozen with the value evaluated at build time, so these values need to be set appropriately when the project is built. If you need access to runtime environment values, you'll have to setup your own API to provide them to the client (either on demand or during initialization)"
Prairie FalconOP
Interesting. Seems like that's for NEXT_PUBLIC env variables, not for regular env variables