socket.io-redis-adapter icon indicating copy to clipboard operation
socket.io-redis-adapter copied to clipboard

TypeError: socket.client.writeToEngine is not a function

Open aintHuman opened this issue 3 years ago • 6 comments

Getting the following error trying to get redis working with socketio and express.

TypeError: socket.client.writeToEngine is not a function at <PROJECT_DIRECTORY>/server/node_modules/@socket.io/redis-adapter/node_modules/socket.io-adapter/dist/index.js:119:31

Few others here have also flagged this, but I don't see any workaround. socket.io-redis-adapter is the latest version, 7.0.0.

My socketio instance is being created like this:

--

// Create the SocketIO Server const express = require('express'); const http = require('http'); const sio = require('socket.io'); const redisAdapter = require('@socket.io/redis-adapter'); const { createClient } = require("redis");

. . . const app = express(); const server = http.createServer(app); const io = new sio.Server(server); const pubClient = createClient({ port : [redacted], host : [redacted], password : [redacted] }); const subClient = pubClient.duplicate() io.adapter(redisAdapter(pubClient, subClient));

aintHuman avatar Nov 02 '21 17:11 aintHuman

It looks like a version mismatch. Could you please check the version of socket.io?

darrachequesne avatar Nov 02 '21 22:11 darrachequesne

socketio version is 4.0.1

aintHuman avatar Nov 02 '21 23:11 aintHuman

Upgrading socketio to 4.3.1 seems to have fixed the issue

aintHuman avatar Nov 02 '21 23:11 aintHuman

@aintHuman how about downgrading the redis adapter to 6.1.1?

awesomelike avatar Nov 03 '21 17:11 awesomelike

Anyways, I think version shouldn't be the problem, as the compatibility table says that redis adapter "6.1.x and above" should match socket.io server of "4.x". image

awesomelike avatar Nov 03 '21 18:11 awesomelike

Hello. I encountered this problem. I got rid of the problem when I updated my packages as below.

"@socket.io/redis-adapter": "^7.2.0",
"redis": "3.1.2",
"socket.io": "4.5.1",

HyopeR avatar Aug 16 '22 13:08 HyopeR

For future readers: this error was due to an incompatibility between the socket.io, socket.io-adapter and @socket.io/redis-adapter packages. Updating to the latest revision should fix the issue.

Please reopen if needed.

darrachequesne avatar May 02 '23 15:05 darrachequesne