Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument of type '(nsp: any) => RedisAdapter' is not assignable to parameter of type 'AdapterConstructor' socket.io version 4.6.0 #4624

Closed
EternalC0der opened this issue Feb 9, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@EternalC0der
Copy link

The bug
I've been using @socket.io/redis-adapter @8.1.0 with socket.io @4.5.4 without any issues.
Now that I upgraded to socket.io 4.6.0 it suddenly stopped working and I'm getting an error.

As it is mentioned in the documents (https://socket.io/docs/v4/redis-adapter/),
This is how my code looks like (simplified for the sake of this issue):

// Typescript
const pubClient = createClient({ url: "redis://localhost:6379" });
const subClient = pubClient.duplicate();

await Promise.all([pubClient.connect(), subClient.connect()]).catch((e) => {
    console.log(`${chalk.hex(pallette.red)('Redis error:')}`, e.message || e)
})

io.adapter(createAdapter(pubClient, subClient)) // <= Error at this line

And I'm getting an error with io.adapter(createAdapter(pubClient, subClient)):

Argument of type '(nsp: any) => RedisAdapter' is not assignable to parameter of type 'AdapterConstructor'.
  Type '(nsp: any) => RedisAdapter' is not assignable to type '(nsp: Namespace<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any>) => Adapter'.
    Type 'RedisAdapter' is missing the following properties from type 'Adapter': _encode, persistSession, restoreSession

To Reproduce
Example in the docs (https://socket.io/docs/v4/redis-adapter/) with latest versions of @socket.io/redis-adapter, socket.io, redis and typescript gives a type error.

Platform:

  • Device: Desktop
  • OS: Windows 11
  • Nodejs: 16.19.0
@EternalC0der EternalC0der added the to triage Waiting to be triaged by a member of the team label Feb 9, 2023
@darrachequesne
Copy link
Member

Hi! It seems you have two different versions of the socket.io-adapter package, which is included by both socket.io and @socket.io/redis-adapter. Could you please check?

$ npm ls socket.io-adapter

We have tried to fix this in version @socket.io/redis-adapter@8.1.0, with socketio/socket.io-redis-adapter@f07ff7b, but it does not seem to be sufficient.

As a workaround, could you try running npm dedupe?

@darrachequesne darrachequesne added bug Something isn't working and removed to triage Waiting to be triaged by a member of the team labels Feb 13, 2023
@quipo
Copy link

quipo commented Feb 15, 2023

having the same issue with @socket.io/mongo-adapter@0.2.1

@darrachequesne
Copy link
Member

@quipo this should be fixed in latest release of the MongoDB adapter: 0.3.0

@remvn
Copy link

remvn commented Feb 23, 2023

I'm having the same issue with @socket.io/cluster-adapter@0.2.1 too.

@faradaytrs
Copy link

Yeah not fixed

@jcjp
Copy link

jcjp commented Mar 23, 2023

I'm having the same issue with @socket.io/cluster-adapter@0.2.1 too.

Same I tried running npm dedupe but still have the same issue also tested the latest socket.io version 4.6.1, I have some details on this closed issue. #4621 (comment).

+-- @socket.io/cluster-adapter@0.2.1
| `-- socket.io-adapter@2.4.0
`-- socket.io@4.6.1
  `-- socket.io-adapter@2.5.2

@darrachequesne
Copy link
Member

For future readers:

We have added socket.io-adapter in the list of peer dependencies of the other adapters, in order to match the version which is imported by the socket.io package:

So this issue does not happen in the future. Please reopen if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants