Next.js Discord

Discord Forum

Does the .env.local file need to be present during the next build step in order for the NEXT_PUBLIC

Unanswered
Mourning Dove posted this in #help-forum
Open in Discord
Mourning DoveOP
variables to be available to send to the front end in production?

Reason being, the next build step happens in a Dockerfile during a GitHub action that builds to Docker container. We want to add the .env.local file after the container is spun up in production.

7 Replies

variables that start with NEXTPUBLIC are inlined in JS files at build time. when spining up instances with the docker images, it's gone.
Mourning DoveOP
So, I cannot simply add the .env.local file in the docker container after the fact eh?
variables with NEXT_PUBLIC are supposed to be used in client side javascript which run on web browsers. so it does not make scenes to have variables in js. you know, web browsers do not have ENV variables.
Mourning DoveOP
right
Mourning DoveOP
Yeah, so when we build the images (and run next build), we don't yet know which environment this images will be deployed to, so the NEXT_PUBLIC_API_URL will be different based on which environment it gets deployed to. This is the problem I'm trying to solve.
it's known issue when using Docker, k8s like that.
Mourning DoveOP
Ok, thanks for your input. I'll try and figure something out.