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

TS2322: Type 'Redis' is not assignable to type 'RedisClient'. #559

Open
intellizetm opened this issue Dec 12, 2022 · 7 comments
Open

TS2322: Type 'Redis' is not assignable to type 'RedisClient'. #559

intellizetm opened this issue Dec 12, 2022 · 7 comments

Comments

@intellizetm
Copy link

my redis-pub-sub.provider.ts like below ;

import { pubSubToken } from '@nestjs-query/query-graphql';
import { RedisPubSub } from 'graphql-redis-subscriptions';
import Redis from 'ioredis';
import { Provider } from '@nestjs/common';

export class RedisPubSubProvider {
  static provider(): Provider {
    return {
      provide: pubSubToken(),
      useFactory: () => {
        const options = {
          host: process.env.REDIS_HOST || 'localhost',
          port: 6379
        };
        return new RedisPubSub({
          publisher: new Redis(options),
          subscriber: new Redis(options)
        })
      } ,
    };
  }
}

and error like ;

[build 7/7] RUN npx nx build driver-api --prod:
#12 6.275
#12 6.276 > nx run driver-api:build:production
#12 6.276
#12 50.06 chunk (runtime: main) main.js (main) 348 KiB [entry] [rendered]
#12 50.06
#12 50.06 ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts
#12 50.06 ./libs/database/src/lib/redis-pub-sub.provider.ts 16:10-19
#12 50.06 [tsl] ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts(16,11)
#12 50.06 TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
#12 50.06 Type 'Redis' is missing the following properties from type 'Redis': stream, isCluster, connector, reconnectTimeout, and 140 more.
#12 50.06
#12 50.06 ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts
#12 50.06 ./libs/database/src/lib/redis-pub-sub.provider.ts 17:10-20
#12 50.06 [tsl] ERROR in /app/libs/database/src/lib/redis-pub-sub.provider.ts(17,11)
#12 50.06 TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
#12 50.06
#12 50.06 ERROR in libs/database/src/lib/redis-pub-sub.provider.ts:16:11
#12 50.06 TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
#12 50.06 Type 'Redis' is missing the following properties from type 'Redis': stream, isCluster, connector, reconnectTimeout, and 140 more.
#12 50.06 14 | };
#12 50.06 15 | return new RedisPubSub({
#12 50.06 > 16 | publisher: new Redis(options),
#12 50.06 | ^^^^^^^^^
#12 50.06 17 | subscriber: new Redis(options)
#12 50.06 18 | })
#12 50.06 19 | } ,
#12 50.06
#12 50.06 ERROR in libs/database/src/lib/redis-pub-sub.provider.ts:17:11
#12 50.06 TS2322: Type 'Redis' is not assignable to type 'RedisClient'.
#12 50.06 15 | return new RedisPubSub({
#12 50.06 16 | publisher: new Redis(options),
#12 50.06 > 17 | subscriber: new Redis(options)
#12 50.06 | ^^^^^^^^^^
#12 50.06 18 | })
#12 50.06 19 | } ,
#12 50.06 20 | };
#12 50.06
#12 50.06 webpack compiled with 4 errors (bc25c10f78b686c1)
#12 50.16
#12 50.16
#12 50.16
#12 50.16 > NX Running target "driver-api:build" failed

@ShannonMasters
Copy link

unfortunately this is because of no ioredis 5 support, if you use ioredis@4.28.5 it should work.

hopefully this lib isn't dead, as I need ioredis 5..

@intellizetm
Copy link
Author

its same issue sir.I coudnt solve this issue for a few months.and my depencies ;

"private": true,
"dependencies": {
"@aginix/nestjs-firebase-admin": "^2.2.0",
"@angular/animations": "14.0.3",
"@angular/cdk": "14.0.3",
"@angular/common": "14.0.3",
"@angular/compiler": "14.0.3",
"@angular/core": "14.0.3",
"@angular/forms": "14.0.3",
"@angular/google-maps": "^14.0.3",
"@angular/platform-browser": "14.0.3",
"@angular/platform-browser-dynamic": "14.0.3",
"@angular/router": "14.0.3",
"@angular/service-worker": "14.0.3",
"@ant-design/icons-angular": "13.1.0",
"@antv/g2": "^4.2.4",
"@apollo/client": "^3.6.9",
"@fastify/cors": "^7.0.0",
"@fastify/multipart": "^6.0.0",
"@fastify/static": "^5.0.2",
"@googlemaps/google-maps-services-js": "^3.3.16",
"@ingameltd/payu": "^1.0.5",
"@liaoliaots/nestjs-redis": "^5.1.1",
"@nestjs-query/core": "^0.30.0",
"@nestjs-query/query-graphql": "^0.30.0",
"@nestjs-query/query-typeorm": "^0.30.0",
"@nestjs/apollo": "^10.0.16",
"@nestjs/axios": "^0.0.8",
"@nestjs/common": "^8.4.7",
"@nestjs/config": "^2.1.0",
"@nestjs/core": "^8.4.7",
"@nestjs/graphql": "^10.0.16",
"@nestjs/jwt": "^8.0.1",
"@nestjs/passport": "^8.2.2",
"@nestjs/platform-fastify": "^8.4.7",
"@nestjs/schedule": "^2.1.0",
"@nestjs/serve-static": "^2.2.2",
"@nestjs/typeorm": "8.0.4",
"@nestjs/websockets": "^8.4.7",
"@nrwl/angular": "14.3.6",
"@nrwl/web": "14.3.6",
"@paypal/checkout-server-sdk": "^1.0.3",
"apollo-angular": "^3.0.1",
"apollo-server-core": "^3.10.2",
"apollo-server-fastify": "^3.10.2",
"autoprefixer": "^10.4.7",
"class-transformer": "0.4.0",
"class-validator": "0.13.2",
"dataloader": "^2.1.0",
"dotenv": "16.0.1",
"graphql": "^15.7.2",
"graphql-redis-subscriptions": "^2.4.2",
"graphql-relay": "^0.9.0",
"graphql-subscriptions": "1.2.1",
"graphql-tools": "^8.2.13",
"instamojo-payment-nodejs": "^3.0.0",
"ioredis": "4.28.5",
"json-2-csv": "^3.17.1",
"jwt-decode": "^3.1.2",
"mercadopago": "^1.5.13",
"mysql": "^2.18.1",
"ng-zorro-antd": "^13.3.2",
"ngx-timeago": "^2.0.0",
"node-rsa": "^1.1.1",
"passport": "^0.6.0",
"passport-jwt": "^4.0.0",
"passport-local": "^1.0.0",
"paystack-node": "^0.3.0",
"paytm-pg-node-sdk": "^1.0.4",
"paytmchecksum": "^1.5.0",
"razorpay": "^2.8.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.5.5",
"stripe": "^9.10.0",
"tslib": "^2.4.0",
"typeorm": "0.2.45",
"zone.js": "0.11.6"
},
"devDependencies": {
"@angular-devkit/build-angular": "14.0.3",
"@angular-eslint/eslint-plugin": "14.0.0",
"@angular-eslint/eslint-plugin-template": "14.0.0",
"@angular-eslint/template-parser": "14.0.0",
"@angular/cli": "~14.0.3",
"@angular/compiler-cli": "14.0.3",
"@angular/language-service": "14.0.3",
"@bartholomej/ngx-translate-extract": "^8.0.2",
"@graphql-codegen/cli": "^2.6.2",
"@graphql-codegen/introspection": "^2.1.1",
"@graphql-codegen/typescript": "^2.5.1",
"@graphql-codegen/typescript-apollo-angular": "^3.4.12",
"@graphql-codegen/typescript-operations": "^2.4.2",
"@nestjs/schematics": "^8.0.11",
"@nestjs/testing": "^8.4.7",
"@ngx-translate/core": "^14.0.0",
"@ngx-translate/http-loader": "^7.0.0",
"@nrwl/cli": "14.3.6",
"@nrwl/eslint-plugin-nx": "14.3.6",
"@nrwl/jest": "14.3.6",
"@nrwl/linter": "14.3.6",
"@nrwl/nest": "14.3.6",
"@nrwl/node": "14.3.6",
"@nrwl/workspace": "14.3.6",
"@nxrocks/nx-flutter": "^3.0.2",
"@tailwindcss/forms": "^0.5.2",
"@tailwindcss/typography": "^0.5.2",
"@types/busboy": "^1.5.0",
"@types/cron": "^2.0.0",
"@types/estree": "0.0.52",
"@types/ioredis": "4.28.10",
"@types/jest": "29.0.0",
"@types/node": "^18.0.0",
"@types/paypal__checkout-server-sdk": "^1.0.4",
"eslint-config-prettier": "8.5.0",
"jest": "29.0.2",
"jest-preset-angular": "12.1.0",
"json-autotranslate": "^1.10.3",
"ng-packagr": "14.0.2",
"nx": "14.3.6",
"postcss": "^8.4.14",
"postcss-import": "14.1.0",
"postcss-preset-env": "7.7.2",
"postcss-url": "10.1.3",
"prettier": "2.7.1",
"tailwindcss": "^3.1.4",
"ts-jest": "29.0.0",
"ts-node": "10.8.1",
"typescript": "4.7.4"
}
}

@ShannonMasters
Copy link

I'm not sure then, the only real differences I see in your deps are a few versions older on things like:
"graphql-redis-subscriptions": "^2.5.0",
"graphql-subscriptions": "^2.0.0",

I'm also using the ptc-org fork of nestjs-query as its actively maintained, but I don't think that's your issue.
"@ptc-org/nestjs-query-core": "^1.1.4",
"@ptc-org/nestjs-query-graphql": "^1.1.4",
"@ptc-org/nestjs-query-typeorm": "^1.1.4",

my provider class that's working with graphql-redis-subscriptions 2.5.0 and ioredis 4.28.5 is below, but it's basically the same (I inject config, and have a date reviver so updatedAt timestamps work).. so not sure it'll help.

import { Provider } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { pubSubToken } from '@ptc-org/nestjs-query-graphql';
import { RedisPubSub } from 'graphql-redis-subscriptions';
import Redis from 'ioredis';

export class RedisPubSubProvider {
  static provider(): Provider {
    return {
      provide: pubSubToken(),
      inject: [ConfigService],
      useFactory: async (config: ConfigService) => {
        const dateReviver = (key, value) => {
          const isISO8601Z = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/;
          if (typeof value === 'string' && isISO8601Z.test(value)) {
            const tempDateNumber = Date.parse(value);
            if (!isNaN(tempDateNumber)) {
              return new Date(tempDateNumber);
            }
          }
          return value;
        };

        const redisOptions = {
          sentinels: config.get<boolean>('SENTINEL_ENABLED')
            ? [
                {
                  host: config.get('REDIS_HOST'),
                  port: config.get('REDIS_PORT'),
                },
              ]
            : undefined,
          host: config.get<boolean>('SENTINEL_ENABLED') ? undefined : config.get('REDIS_HOST'),
          password: config.get('REDIS_PASSWORD'),
          sentinelPassword: config.get<boolean>('SENTINEL_ENABLED')
            ? config.get('REDIS_PASSWORD')
            : undefined,
          name: config.get<boolean>('SENTINEL_ENABLED') ? 'mymaster' : undefined,
        };

        return new RedisPubSub({
          publisher: new Redis(redisOptions),
          subscriber: new Redis(redisOptions),
          reviver: dateReviver,
        });
      },
    };
  }
}

@yardenxr
Copy link

after updating from ioredis 5.2.4 to 5.3.1 i got the same error.

@dipanshu2dj
Copy link

after updating from ioredis 5.2.4 to 5.3.1 i got the same error.

I am also getting the same error on package update. Hence stuck for now with the older ioredis.

@amille44420
Copy link

amille44420 commented Apr 23, 2024

The only way working out for me is to force the ioredis version for all packages by adding it to the resolutions in package.json ; as long as there's no breaking change between the version you're forcing in and the version initially used by the packages then it should work as expected.

The breaking changes from v5.0.0 does not seem to be an issue, or so far I never got to see it.

@cam-at-tactiq
Copy link

Hi @davidyaha can you please pin the ioredis dependency in Package.json to a verion that works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants