MetinSeylan / Vue-Socket.io

😻 Socket.io implementation for Vuejs and Vuex
https://metin.sh
MIT License
3.95k stars 499 forks source link

Error on Vue3 cannot set properties of undefined (setting '$socket') #323

Open meroo36 opened 3 years ago

meroo36 commented 3 years ago

In node_modules/vue-socket.io/dist/vue-socketio.js there is a line as:

{t.prototype.$socket=this.io,t.prototype.$vueSocketIo=this,t.mixin(n),i.info("Vue-Socket.io plugin enabled")}

I just changed the line as:

{t.config.globalProperties.$socket=this.io,t.config.globalProperties.$vueSocketIo=this,t.mixin(n),i.info("Vue-Socket.io plugin enabled")}

Simply changed "t.prototype"'s to "t.config.globalProperties"'s, and it works but don't know if it is the right solution.

ashantyk commented 2 years ago

so basically no vue 3 support yet

Rebehy commented 2 years ago

I have also had to use @meroo36 solution to prevent this error.

terrykingdev commented 2 years ago

It seems although npm says it's v3.0.10 it doesn't have the last Vue 3 fix. When installing it's probably easier to: npm i https://github.com/MetinSeylan/Vue-Socket.io.git
That works for me with Vue 3. But why isn't npm correct?

devaku commented 2 years ago

It's August 15th, 2022, and this error still persist even with me using Vue 3. Is anyone going to update the npm entry?

SeriousVitamin commented 2 years ago

I got same error with Vue 3, meroo36 solution works for me too.

Jak3d commented 1 year ago

Problem still present to this day on Vue 3, meroo36's solution works.

narenkram commented 5 months ago

It seems although npm says it's v3.0.10 it doesn't have the last Vue 3 fix. When installing it's probably easier to: npm i https://github.com/MetinSeylan/Vue-Socket.io.git That works for me with Vue 3. But why isn't npm correct?

It works, thank you so much.