socketio / socket.io-redis-streams-adapter

The Socket.IO adapter based on Redis Streams, allowing to broadcast events between several Socket.IO servers.
https://socket.io/docs/v4/redis-streams-adapter/
MIT License
30 stars 15 forks source link

requires redis npm package even when using ioredis #24

Closed derevnjuk closed 5 months ago

derevnjuk commented 6 months ago

When using @socket.io/redis-streams-adapter with ioredis, the application fails to start due to an unresolved module error. It appears that redis npm package is required, despite using ioredis.

Steps to Reproduce:

  1. Set up a new project with the dependencies listed below.
  2. Use the provided code snippet in main.ts.
  3. Run the project.

Here is a minimal reproducible example:

// main.ts
import { Redis } from "ioredis";
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/redis-streams-adapter";

const redisClient = new Redis();

const io = new Server({
  adapter: createAdapter(redisClient)
});

io.listen(3000);
{
  "name": "test",
  "dependencies": {
    "@socket.io/redis-streams-adapter": "0.2.1",
    "ioredis": "5.2.6",
    "socket.io": "^4.7.5"
  }
}

Expected Behavior: The adapter should work usingioredis without requiring the redis package.

Actual Behavior: Throws an error stating that the redis module cannot be found.

Logs:

Error: Cannot find module 'redis'
Require stack:
- /home/node/app/node_modules/@socket.io/redis-streams-adapter/dist/util.js
- /home/node/app/node_modules/@socket.io/redis-streams-adapter/dist/adapter.js
- /home/node/app/node_modules/@socket.io/redis-streams-adapter/dist/index.js
- /home/node/app/main.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    ...
Code: 'MODULE_NOT_FOUND'
Require stack:
- /home/node/app/node_modules/@socket.io/redis-streams-adapter/dist/util.js
- /home/node/app/node_modules/@socket.io/redis-streams-adapter/dist/adapter.js
- /home/node/app/node_modules/@socket.io/redis-streams-adapter/dist/index.js
- /home/node/app/main.js
darrachequesne commented 5 months ago

This should be fixed by https://github.com/socketio/socket.io-redis-streams-adapter/commit/a2f3f5aeaf2a1b171bc094d0fe3b9fb2996fcd54, included in version 0.2.2. Thanks for the heads-up!