简体   繁体   中英

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" .

Is this API deprecated? Or something wrong with my code?

I found it's something wrong with my database, not socket.io. It's fixed now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM