Nextjs14 Docker Public Env
Unanswered
Patagonian Sheepdog posted this in #help-forum
Patagonian SheepdogOP
hello
I am using next js 14. NEXT_PUBLIC works on the server, but it does not work on the client side. This may be the reason.
I am using next js 14. NEXT_PUBLIC works on the server, but it does not work on the client side. This may be the reason.
14 Replies
@Patagonian Sheepdog hello
I am using next js 14. NEXT_PUBLIC works on the server, but it does not work on the client side. This may be the reason.
Thrianta
How do you use the env variable in the client?
You should prefix it on the use also
process.env.NEXT_PUBLIC_SOMETHINGPatagonian SheepdogOP
Yes, it works when I build normally and start, but the ones on the client side do not work in the Docker environment. @Chartreux
Thrianta
Maybe you forgot setting up the env variables for Docker environment?
Patagonian SheepdogOP
No, I'm sure I set it up properly, I can see it on the server, but I can't see it on the client side.
Thrianta
process.env['NEXT_PUBLIC_SOMETHING']Have you tried this way? Or debugging the process in the client?
Entlebucher Mountain Dog
i'm getting the same issue @Patagonian Sheepdog did you solve it?
Somali
I am having the same problem here. If I read it correctly we can only access
(https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#loading-environment-variables)
NEXT_PUBLIC_SOMETHING on client side only if that env is exposed on build?(https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#loading-environment-variables)
I bundle my docker image before pushing it, I guess I need to do it on the build phase?
Somali
following this discussion here: https://github.com/vercel/next.js/discussions/44628, I figured out it's better to either put the env var in the docker build step or use this package: https://github.com/expatfile/next-runtime-env (more updated than the other one)
shameless ping to @Patagonian Sheepdog