Reputation: 51
config
export default () => ({
SECRET: process.env.SECRET,
REDIS: {
password: process.env.PASSWORD,
port: process.env.PORT
}
})
app.module
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 { }
what i do wrong? i had this error
[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 */ ]
})
i think i did exactly what describe in nest doc if i use just RediseModule.register(simpleJsonConfig) all work but i want this way with config service Can someone explain?
Upvotes: 1
Views: 2288
Reputation: 51
need just add import
RedisModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => configService.get('REDIS') || {}, // or use async method
inject: [ConfigService]
}),
Upvotes: 4