javascript - Socket.io - UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“发出”
问题描述
我写了这个:
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。现在已经修好了。
推荐阅读
- mysql - MySql 错误 1093 尝试使用两个数据库和两个表进行更新
- azure-sql-database - 存储过程中的文件处理 - Azure SQL 无服务器数据库
- reporting-services - 在 ssrs 报告的每一页上重复多行
- java - 如何在矩形框中制作透明的黑色。(颜色为黑色,但需要透明,需要显示后面的屏幕)
- reactjs - 如何在redux工具包中推送reducer状态的数组值?
- docker - docker swarm macvlan 网络问题
- python-requests - 如何将请求代码转换为scrapy?
- javascript - 检测用户是否存在于 Discord 客户端 (Discord.js)
- spring-batch - 从 Spring Batch 中的多个表中删除记录
- wso2 - 从特定 API 公开有限方法:WSO2 API Manager 版本 2.6.0 免费