#TS2614: Module  "redis"  has no exported member  createClient .

25 messages · Page 1 of 1 (latest)

lofty temple
#

Hello,

After removing the redis package from my Node project and then re-adding it, I haven't been able to import createClient. I keep getting the error: Module '"redis"' has no exported member 'createClient'. Did you mean to use 'import createClient from "redis"' instead?

I was originally on version 4.6.6 and am now on the latest, and am experiencing this error. Additionally, I have also tried downgrading back to version 4.6.6 and still experienced the same error.

Below is my code:

import {createClient} from "redis"

const config = JSON.parse(process.env.CONFIG || "{}")

const client: any = createClient({
    socket: {
        host: config.redis.host as string,
        port: config.redis.port as number,
    },
    username: config.redis.username as string || undefined,
    password: config.redis.password as string || undefined,
    database: config.redis.db as number
})

client.connect()

client.on("error", (err: any) => console.warn(`[Vixlatio/Backend-Services/Redis] ${err}`))
client.on("connect", () => console.info("[Vixlatio/Backend-Services/Redis] Client connected"))

export default client
digital crown
#

Are you by any chance using ESM?

lofty temple
#

"target": "es6",
"module": "commonjs",
"moduleResolution": "bundler",

#

I have also tried ESNext

digital crown
#

Highly advise against using module: cjs thats meant for really really old projects, and im not even sure it works property with new target options

lofty temple
#

I'll also add that I installed ioredis before installing redis again (Though I have uninstalled it). Not sure if that affects redis in any way

lofty temple
#

Yeah, it worked in a new project for me too

#

Not sure why it's not working with our one anymore though

digital crown
#

its most likely because of your tsconfig

lofty temple
#
// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": "./",
    "target": "es6",
    "incremental": true,
    "types": [
      "reflect-metadata",
      "node",
      "@types/sequelize"
    ],
    "typeRoots": [
      "@/types"
    ],
    "module": "ESNext",
    "moduleResolution": "bundler",
    "sourceMap": true,
    "outDir": "out",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "noImplicitReturns": false,
    "strictNullChecks": true,
    "strictPropertyInitialization": false,
    "resolveJsonModule": true,
    "paths": {
      "@/*": [
        "./*"
      ]
    }
  }
}
digital crown
#

oh you are using types

#

add redis to the types array

lofty temple
#

Done, though it's still erroring the same thing

digital crown
lofty temple
digital crown
#

what if you remove the typeRoots option as well? 🤔

lofty temple
#

sure, though it'll break the app

#

didn't resolve the issue

digital crown
#

weird...
do you happen to have type: module in your package.json?

lofty temple
#

nope

digital crown
#

does it error if you use the redis client directly? import { createClient } from "@redis/client"

lofty temple
#

no