简体   繁体   English

Socket.io - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emit' of undefined

[英]Socket.io - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emit' of undefined

I wrote this:我写了这个:

io.sockets.connected[socketId].emit() // I'm sure `socketId` exists and connected.

But an error occurs:但是会出现错误:

(node:2416) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'emit' of undefined
    at ~/transmister/transmister-server-and-web/server.js:71:60
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:2416) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)

My Socket.io version is "socket.io": "^2.3.0" .我的 Socket.io 版本是"socket.io": "^2.3.0"

Is this API deprecated?这个 API 是否已弃用? Or something wrong with my code?还是我的代码有问题?

I found it's something wrong with my database, not socket.io.我发现我的数据库有问题,而不是 socket.io。 It's fixed now.现在已经修好了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Socket.IO TypeError:无法读取未定义的属性“发出” - Socket.IO TypeError: Cannot read property 'emit' of undefined Socket.io:“无法读取未定义的属性&#39;emit&#39;” - Socket.io : “Cannot read property 'emit' of undefined” AngularJS Socket.io:无法读取未定义的属性“ emit” - AngularJS Socket.io: Cannot read property 'emit' of undefined Socket.io 未捕获类型错误:无法读取未定义的属性“应用” - Socket.io Uncaught TypeError: Cannot read property 'apply' of undefined Socket.io TypeError:无法读取未定义的属性“hteam” - Socket.io TypeError: Cannot read property 'hteam' of undefined Socket.io引发“ TypeError:无法读取未定义的属性&#39;push&#39;” - Socket.io raises “TypeError: Cannot read property 'push' of undefined” WebRTC,socket.io,node.js:无法读取未定义的属性&#39;emit&#39;? - WebRTC , socket.io, node.js: Cannot read property 'emit' of undefined? 使用React / Socket.IO无法读取未定义错误的属性&#39;emit&#39; - Cannot read property 'emit' of undefined error using React/Socket.IO 当socket.io发出“登录”消息时,TypeError:无法读取未定义的属性“ navigate” - When socket.io emits to 'login', TypeError: Cannot read property 'navigate' of undefined UnhandledPromiseRejectionWarning TypeError:无法读取未定义的属性“属性” - UnhandledPromiseRejectionWarning TypeError: Cannot read property 'property' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM