socketio / socket.io-admin-ui

Admin UI for Socket.IO
https://admin.socket.io
MIT License
358 stars 95 forks source link

Cannot read property 'on' of undefined #49

Closed luettgau closed 2 years ago

luettgau commented 2 years ago

I'am trying to get admin-ui to work, but I always get this error from the node_module, when inserting:

instrument(io, { auth: false, });

Any ideas to fix this?

[INFO] 17:33:57 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.9.1, typescript ver. 4.7.4) TypeError: Cannot read property 'on' of undefined at registerEngineListeners (/Volumes/Privat/Code/projects/socketio-server/node_modules/@socket.io/admin-ui/dist/index.js:366:15) at instrument (/Volumes/Privat/Code/projects/socketio-server/node_modules/@socket.io/admin-ui/dist/index.js:424:5) at Object.<anonymous> (/Volumes/Privat/Code/projects/socketio-server/src/index.ts:48:11) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Module._compile (/Volumes/Privat/Code/projects/socketio-server/node_modules/source-map-support/source-map-support.js:568:25) at Module.m._compile (/private/var/folders/73/1v90d1r53836q4zfl33hpb400000gp/T/ts-node-dev-hook-5528744062605151.js:69:33) at Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at require.extensions..jsx.require.extensions..js (/private/var/folders/73/1v90d1r53836q4zfl33hpb400000gp/T/ts-node-dev-hook-5528744062605151.js:114:20) at require.extensions.<computed> (/private/var/folders/73/1v90d1r53836q4zfl33hpb400000gp/T/ts-node-dev-hook-5528744062605151.js:71:20) at Object.nodeDevHook [as .ts] (/Volumes/Privat/Code/projects/socketio-server/node_modules/ts-node-dev/lib/hook.js:63:13) [ERROR] 17:33:57 TypeError: Cannot read property 'on' of undefined

darrachequesne commented 2 years ago

Hi! Have you found a solution?

loczek commented 2 years ago

I encountered the same issue. The problem was that the socket io server was a standalone server and not a http server.

This does't work

const io = new Server({
 cors: {
    origin: ["https://admin.socket.io"],
    credentials: true,
  },
});

instrument(io, {
  auth: false,
});

io.listen(5000)

and this does

const httpServer = createServer();

const io = new Server(httpServer, {
  cors: {
    origin: ["https://admin.socket.io"],
    credentials: true,
  },
});

instrument(io, {
  auth: false,
});

httpServer.listen(5000)
darrachequesne commented 2 years ago

This should be fixed by https://github.com/socketio/socket.io-admin-ui/commit/b21b649ea246eec87af121ffe676c876b001de05, included in release 0.5.1. Thanks!