如何解决Socket.io-UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ emit”
我写了这个:
io.sockets.connected[socketId].emit() // I'm sure `socketId` exists and connected.
但是发生错误:
(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)
我的Socket.io版本为"socket.io": "^2.3.0"
。
此API是否已弃用?还是我的代码有问题?
解决方法
我发现我的数据库有问题,而不是socket.io。现在已修复。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。