question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: Cannot set property '$socket' of undefined

See original GitHub issue

`TypeError on Vue 3 with Typescript while installing the plugin with the new createApp.use() API.

main.ts

const vSocket = new VueSocketIO({
    debug: true,
    connection: 'http://localhost:4000',
    /*  vuex: {
         store,
         actionPrefix: 'SOCKET_',
         mutationPrefix: 'SOCKET_'
     }, */
    /*  options: { path: "/my-app/" } //Optional options */
})
createApp(App).use(store).use(vSocket).mount('#app')

the error is

vue-socketio.js?5132:10 Uncaught TypeError: Cannot set property '$socket' of undefined
    at t.value (vue-socketio.js?5132:10)
    at Object.use (runtime-core.esm-bundler.js?5c40:3360)
    at eval (main.ts?bc82:19)
    at Module../src/main.ts (app.js:1115)
    at __webpack_require__ (app.js:849)
    at fn (app.js:151)
    at Object.1 (app.js:1140)
    at __webpack_require__ (app.js:849)
    at checkDeferredModules (app.js:46)
    at app.js:925

I think the problem is with the plugin installation while using Vue 3 with Typescript.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
soulsam480commented, Oct 12, 2020

I think I figured out the problem. In Vue 3 when a plugin installs, the install function receives two parameters which are app from Vue 3’s createApp method and options set by the user. [https://v3.vuejs.org/guide/plugins.html#writing-a-plugin](Vue 3 plugins).

So I think the problem is when the plugin installs and sets the instance method $socket using Vue 2’s Vue.prototype it breaks on Vue 3 as there is no such method. Instead, Vue 3 uses app.config.globalProperties.$some_global_method .

I’m requesting the author @MetinSeylan to please have a look into this as Vue 3 has been released as stable.

6reactions
livtechcommented, Jul 26, 2021

I downloaded vue socket from npm, but the /dist/vue-socketio.js still with t.prototype , and the file from GitHub is with t.config.globalProperties. Have same way to update the npm?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Socket.io - TypeError: Cannot set properties of undefined ...
I was told that data is overwritten by using socket.data = value . If I change it to socket.socketDate for example, then it...
Read more >
typeerror: cannot set properties of undefined (setting 'status')
The error is that can't set "whatever" on undefined . This is this line of code: window.localAudio.srcObject = stream; and it means localAudio...
Read more >
vue-socket.io Cannot set property '$socket' of undefined 解决 ...
看了vue-socket.io 作者好像没啥心情更新依赖,提交的也没怎么管,无奈,直接debugger着调吧。 对是这个报错,很明显是挂载vue出了问题,看了源码,vue.
Read more >
Uncaught TypeError: Cannot set property '$socket' of undefined -
Uncaught TypeError: Cannot set property '$socket' of undefined ... `TypeError on Vue 3 with Typescript while installing the plugin with the new ...
Read more >
Uncaught TypeError: Cannot set property
In JavaScript almost everything is an object, null and undefined are exception. When you try to access an undefined variable it always returns...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found