Module '"redis"' has no exported member 'RedisClient'
Asked Answered
D

2

7

I am creating a multi-node Express/Socket.io server using Typescript and I am trying to import RedisClient from redis, but I can't get it to work because I get the error

Module '"redis"' has no exported member 'RedisClient'

It seems to be trying to retrieve it form

node_modules/redis/dist/index

But in reality it is here:

node_modules/@types/redis"

How can I get it to import from the right place?

Duplex answered 6/12, 2021 at 20:17 Comment(1)
I ended up copying the contents of the file in "node_modules/@types/redis" and pasting them at the end of the file in "node_modules/redis/dist/index". That made the problem go away, but I am sure this can't be sustainable solution. I hope there is a better solution to this out there.Duplex
M
3

Looks like Redis package has been officially updated to v4 recently, which introduced some breaking changes, including several interface changes.

I recommend to temporarily use the v3 until all your dependencies (including @types/redis) are properly updated:

npm install redis@3
Mu answered 7/12, 2021 at 11:21 Comment(0)
D
1

After checking for some time I realized that things changed and the documentation states that you now do NOT need to use RedisClient. You now need to use:

import { createClient } from "redis";

This is what things look like now:

const pubClient = createClient({ url: `redis://<path to redis>:6379` });
Duplex answered 31/12, 2021 at 23:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.