useElementSize is not defined, when deploy on kubernetes
Hello 👋
I try to deploy a nuxt ui pro template to a kubernetes cluster. Everything fine, the app is successfully deployed + alive.
But when i create a simple port-forward on it and I load the app i got
If you need any further information, please do not hesitate to ask me 🙂
useElementSize is not defined
.
But unfortunately, when I run the same image locally i don't get the error. Have you ever heard of this issue ?
My dockerfile :
My deployment file (k8s) :
My service file :
Thanks for your help 🙏If you need any further information, please do not hesitate to ask me 🙂
25 Replies
🤔 probably, i will try to fix with your suggestion. But really strange i only got this issue when deploy on kubernetes and not when in run the image locally
It doesn't change anything unfortunately :/
By deactivating SSR, I no longer have the problem, however I am always interested if you have other ideas / explanations to solve this issue
I have the same problem with
useElementSize
and also useWindowSize
. Local build works just fine but gives the same error when built in a containerYes definitely
It come from this template on NUXT UI PRO : https://github.com/nuxt-ui-pro/dashboard
And this line : https://github.com/nuxt-ui-pro/dashboard/blob/4c749ad9c6a3bf7f62063752d08c6a55de00dbdc/pages/index.vue#L52
( i work with @Elkios - Mathys )
Yes it's the code
Yep
When i'm doing this, the error do not persist, but new error appear
Yep ahah
The new error is......
Cannot read properties of null (reading 'isCE')
🥲
Okok thanks, i'll try to use ClientOnly of transpose a library and back to you
Thanks-you@L422Y I didn't have
vueuse/core
installed and when I installed it the error disappeared. But why does this work on a local build and not in docker?Works for us too, thanks 🙏
For anyone who stumbles on this. I'm using
pnpm
and the problem was that I wasn't copying .npmrc
in my Dockerfile along with package.json
& pnpm-lock.yaml
.
The .npmrc
includes shamefully-hoist=true
which when was missing caused the problem.
Copying .npmrc
and deleting vueuse/core
(only have vueuse/nuxt
now) works correctly
This is my dockerfile now
Note: You can remove the docker stages dev and build and run both of them in base. Makes no difference, just causes less confusion.
The prod stage... don't build it on base. Use a clean node image. (You don't need pnpm or the node_modules there)
Thanks a lot, I'm starting to learn about Docker and I have a few questions if you don't mind
1. I use the same Dockerfile for both local dev and prod build by attaching
--target=dev
or --target prod
to the docker run
command, How would I do that if I don't have multistages? Also I don't see a dev command in your file
2. Should I use --mount=type=cache
? I don't know if its Docker-specific or bun's. I'll google it but appreciate any hints
3. You're absolutely right about using node as image for build that's dumb of me 😅 Thanks! I'll do thatOh, sure! I use that specific dockerfile for prod builds only. For my dev env I utilize vscodes devcontainers, and I love them! You can use this dockerfile for both scenarios though, by using
--target builder
and running it with bash
on the command line - I just wouldn't recommend that since you'd usually mount your code into the container instead of copying it.
The cache is a docker-feature and does speed up package installations especially if you run them more often, like in ci pipelines.
And bun... I started this project 3 months ago and decided to give bun a shot since it claimed to be faster than the others. And so far, I'm very happy with that.I've tried dev containers but didn't work out so I went with multistage, will try it out again.
I'm using bun for a side project and also loving it but for this project I have to use node for now as this is a team decision, maybe I'll convince them one day 😁
Devcontainers are awesome, using them since they appeared first, almost 4 years ago
I'm looking at this to see what was I doing wrong https://www.youtube.com/watch?v=b1RavPr_878
Visual Studio Code
YouTube
Get Started with Dev Containers in VS Code
Learn how Dev Containers can boost your coding productivity and save you time configuring your development environment. Follow along with the demo to discover how to set up and use Dev Containers in Visual Studio Code effortlessly. ⚡️💻
Dev Containers Extension: https://aka.ms/DevContainersExtension
Dev Containers Open Specification: https://con...
If you have questions, shoot. I'd be happy to help you out.
Actually I'm stuck with a problem now and posted about it but got no answer so far. I'd appreciate if you can take a look https://discord.com/channels/473401852243869706/1227323622897614858
for a quick start
I think I've seen your issue. Easy solution: Docker host networking
Thank so much for the great help 🙏 I'll search for host networking and follow up on that thread
start the container with
--net host
I tried that but no luck
and change the host you're contacting to 127.0.0.1 🙂
I'll try that and get back to you
(
--net host
actually removes the network encapsulation from the docker container, it's like the stuff running inside and the services on the outside are on the same system)
(But please don't do that in a production system)I've read about it and tried but it didn't work, I'll try it again
@Flo I've tried
--net host
and it didn't work again. It turns out it doesn't work on Windows. The docker.internal.host
works on first request but not on subsequent requests from the browser as it doesn't resolve it correctly. I've tried to add 127.0.0.1 docker.internal.host
to my local machine etc/hosts
file to workaround that but gave issues. I ended up using Dockerfile for production and writing perquisites for local developmentOuh, Windows... 😮
I'm afraid I can't help much with that... I'd switch to a docker compose file in your case, running the laravel server in another container.
I've found out that I'll need to do that eventually anyways yeah