'Module '"redis"' has no exported member 'RedisClient'
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?
Solution 1:[1]
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
Solution 2:[2]
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` });
Solution 3:[3]
I fixed it by inserting
export type RedisClient = ReturnType;
into "node_modules/redis/dist/index.d.ts"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | FRoBa |
| Solution 2 | Rookie |
| Solution 3 |
