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:
- Created 3 years ago
- Reactions:5
- Comments:11 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 andoptions
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’sVue.prototype
it breaks on Vue 3 as there is no such method. Instead, Vue 3 usesapp.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.
I downloaded vue socket from npm, but the /dist/vue-socketio.js still with
t.prototype
, and the file from GitHub is witht.config.globalProperties
. Have same way to update the npm?