nestjs-redis 报 Please make sure that the argument ModuleRef at index [1] is available in the RedisCo

编程入门 行业动态 更新时间:2024-10-25 02:25:18

nestjs-redis 报 Please make sure that the <a href=https://www.elefans.com/category/jswz/34/1745879.html style=argument ModuleRef at index [1] is available in the RedisCo"/>

nestjs-redis 报 Please make sure that the argument ModuleRef at index [1] is available in the RedisCo

nestjs-redis 报错的解决方案

环境

nest8 nestjs-redis

nestjs-redis 报 Please make sure that the argument ModuleRef at index [1] is available in the RedisCoreModule context.

貌似是nestjs-redis 一直没人维护,对nest8以上支持有问题,具体可以看GitHub的issues,一定自己去看

“nestjs-redis”: “^1.3.3”,

Nest can't resolve dependencies of the RedisCoreModule (Symbol(REDIS_MODULE_OPTIONS), ?). Please make sure that the argument ModuleRef at index [1] is available in the RedisCoreModule context.

Potential solutions:
- If ModuleRef is a provider, is it part of the current RedisCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within RedisCoreModule?
  @Module({
    imports: [ /* the Module containing ModuleRef */ ]
  })

解决方案

nestjs-redis 改为 @chenjm/nestjs-redis 这是本人克隆之后自己用的,看了issues自己判断,某些人大可不必上来就喷,这里只是说明如何解决的,如果有好的,希望不吝赐教。

yarn add @chenjm/nestjs-redis

app.module.ts 模块中引入

app.module.ts

import {
    RedisModule
} from "@chenjm/nestjs-redis";

@Module({
    imports: [
        RedisModule.forRoot({
            closeClient: true,
            readyLog: true,
            config: {
                namespace: 'default',
                host: '127.0.0.1',
                port: 6380,
                password: 'redispassword'
            }
        }),
        CatsModule
    ]
})
export class AppModule {}

也可以配合 @nestjs/config 通过configService 提供配置

import { ConfigModule, ConfigService } from "@nestjs/config";
import { RedisModule } from "@chenjm/nestjs-redis";

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      cache: true,
      envFilePath: `${process.env.NODE_ENV}.env`,
      load: [configuration],
    }),
    RedisModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          closeClient: true,
          readyLog: true,
          config: configService.get("redis"),
        };
      },
    }),
  ],
})
export class AppModule {}

更多推荐

nestjs-redis 报 Please make sure that the argument ModuleRef at index [1] is avai

本文发布于:2023-07-30 13:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1250170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:argument   redis   nestjs   RedisCo   index

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!