我在nestjs redis中使用configService时出错,就像在文档中一样

我在nestjs redis中使用configService时出错,就像在文档中一样,nestjs,Nestjs,配置 应用程序模块 export default () => ({ SECRET: process.env.SECRET, REDIS: { password: process.env.PASSWORD, port: process.env.PORT } }) 我做错了什么?我犯了这个错误 import { AuthModule } from './modules/auth/auth.module'; import { UserModule } from '

配置

应用程序模块

export default () => ({
  SECRET: process.env.SECRET,
  REDIS: {
    password: process.env.PASSWORD,
    port: process.env.PORT
  }

})
我做错了什么?我犯了这个错误

import { AuthModule } from './modules/auth/auth.module';
import { UserModule } from './modules/user/user.module';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm'
import config from '../config/config'
import { RedisModule } from 'nestjs-redis'

@Module({
  imports: [
    TypeOrmModule.forRoot(),
    ConfigModule.forRoot({ load: [config] }),
    RedisModule.forRootAsync({
      useFactory: (configService: ConfigService) => configService.get('REDIS') || {},         // or use async method
      inject: [ConfigService]
    }),
    UserModule,
    AuthModule,

  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule { }

我想我做了nest doc中描述的事情 如果我只使用RediseModule.register(simpleJsonConfig),那么所有这些都可以工作,但我希望配置服务采用这种方式 有人能解释一下吗?

只需添加导入即可

[Nest] 4197   - 09/20/2020, 10:08:21 PM   [ExceptionHandler] Nest can't resolve dependencies of the Symbol(REDIS_MODULE_OPTIONS) (?). Please make sure that the argument ConfigService at index [0] is available in the RedisCoreModule context.

Potential solutions:
- If ConfigService is a provider, is it part of the current RedisCoreModule?
- If ConfigService is exported from a separate @Module, is that module imported within RedisCoreModule?
  @Module({
    imports: [ /* the Module containing ConfigService */ ]
  })
 +2ms
Error: Nest can't resolve dependencies of the Symbol(REDIS_MODULE_OPTIONS) (?). Please make sure that the argument ConfigService at index [0] is available in the RedisCoreModule context.

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

[Nest] 4197   - 09/20/2020, 10:08:21 PM   [ExceptionHandler] Nest can't resolve dependencies of the Symbol(REDIS_MODULE_OPTIONS) (?). Please make sure that the argument ConfigService at index [0] is available in the RedisCoreModule context.

Potential solutions:
- If ConfigService is a provider, is it part of the current RedisCoreModule?
- If ConfigService is exported from a separate @Module, is that module imported within RedisCoreModule?
  @Module({
    imports: [ /* the Module containing ConfigService */ ]
  })
 +2ms
Error: Nest can't resolve dependencies of the Symbol(REDIS_MODULE_OPTIONS) (?). Please make sure that the argument ConfigService at index [0] is available in the RedisCoreModule context.

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