New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
env property fails in docker environment #618
Comments
Hi, We need more details and code snippets to help you. |
Hey @squarenomad could you solve that issue? I have the exact same issue! |
We are heavily using docker containers for nuxt based projects at fandogh. There are some facts about different envs: System wide environment variables (using docker env)Assessable in SSR side only with Environment variables passed via
|
@pi0 Do we still have the problem with passing system environment variables during run time ? I have to pass variables during runtime phase and client is not able to pull in the variables. Is there a work around for this issue ? |
@thecodr Unfortunately no, that's not a problem but more a fact about client side bundling! For runtime settings, you can easily use vuex store and fill it on server side. |
@pi0 Is there any reference for filling vuex store on server side ? I tried several times and failed. Some kind of reference will be really helpful. For us, the entire config resides on s3 in json format. We should load that configuration dynamically into vuex store on server side. We should be able to fill the store even before the site loads completely. Thats exactly the place where I am stuck. The vuex store is being populated after the site is loaded :( |
@pi0 This bit me too hard 😅, well we now just build the image using build args and environment settings at build time. Sure it produces host-dependent images and its not pretty but if it works then Its fine at the moment. In the future, can nuxt set the variables at startup way before the app is starting to serve requests? because like docker, any build produced is host dependent and isn't portable, and hard coding the variables seems to break cohesion between server and client, specially if using the express template settings. |
it's definitely an design issue when you replace environment variables at build time and make it impossible to access them at runtime (because they was replaced with plane strings). We for example need env variables to set microservice configs at runtime inside docker containers. It's not possible to rely on buildtime cars or put that stuff inside the container before shipping it. Currently we just run the build process inside the deployed container the first time to get the vars. But the that is not a solution as it demands processing time where it dose not belong. The VueX solution that was mentioned does not feel right ether to be honest. My question: Could there be a small script that injects That variables without running a full build? |
@appinteractive I really hope we finally find some workaround like that script you mentioned. But that injection corrupts chunk hashes! Another idea would be including a generated script in For the microservices problem you mentioned above, I strongly suggest using proxy module. We are using Docker deployments a lot for our projects and it almost resolved our problems :) |
@pi0 It'll be great if there is an example using Using the same nuxt app docker image --> passing different Thanks ! |
Yeah would be interested in an example too. I don’t know how to switch it ether without the correct environment variables. And the proxy only works for url not for the issue of configurations ether. So there is no way around of correctly implementing environment variables on the server site or at least giving a workaround for that. Also the proxy solution has issues with high traffic, there was an unresolved issue that is flying around for some years now. (Didn’t recheck the status) |
I wrote a blog post about this. |
[ Nuxt 1.4.1 ] I have a case have some similar run-time env problem. and I want env apply to vue mounted process , but , I got undefined or env value that when I build nuxt image. seems like we can't use node env on runtime nuxt.js @pi0 , sorry about tag you , Can we have some way to set run-time env to nuxt server , and it overwrite webpack env setting on run-time easier ? or it will be nxut 2.0 can implement ? thanks . |
+1 for runtime env vars in Nuxt. This is such a common problem, that should be handled by the framework instead of everyone building their own version of this. As many others I want to be able to configure my docker containers at run time, specifically I am setting urls to other services within a cluster and I don't want to hardcode those in the docker images, nor I want my containers startup time to increase due to always having to perform nuxt build when I need to scale (add more containers of the same image). |
+1 I have the same problem. |
+1 Same problem |
+1 same probem in nuxt 2.1 |
okay. I have strange problem. I am passing |
@Lahori-Jawan env variables are set at BUILD time. |
@aldarund no. ARG & ENV both variables are set at build time but |
@Lahori-Jawan you are missing what im saying. I`m not talking about docker envs. Nuxt bundle environment variables into bundle at build time. So what is matter what variables are set when u do nuxt build, not a nuxt start |
@aldarund I surely missed that. I will try it & update you on this. |
If u need runtime env variables you can use https://github.com/samtgarson/nuxt-env ( |
@aldarund I think the only best option I have right now is to NOT run build while building the image instead do it when creating container. Do you think its good practice? which I guess is good when there is no 2nd way of doing this. |
my use case is to set live environment credentials for |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Nuxt can't seem to pull environment variables from within a docker environment. When following this example, the baseUrl defaults to the empty string while running in a node docker environment (node:latest docker image), whereas it populated with said env variable if running on a non-containerized host.
The text was updated successfully, but these errors were encountered: