#Error in UsersService

1 messages · Page 1 of 1 (latest)

small hare
#
@Injectable()
export class UsersService {
  constructor(
    @InjectRepository(User) private readonly userRepository: Repository<User>,
    @InjectRepository(Verification)
    private readonly verificationRepository: Repository<Verification>,
    private readonly mailService: MailerService,
  ) {}
// code...
}
Error: Nest can't resolve dependencies of the UsersService (?, VerificationRepository, MailerService). Please make sure that the argument UserRepository at index [0] is available in the AppModule context.

Potential solutions:
- Is AppModule a valid NestJS module?
- If UserRepository is a provider, is it part of the current AppModule?
- If UserRepository is exported from a separate @Module, is that module imported within AppModule?
  @Module({
    imports: [ /* the Module containing UserRepository */ ]
  })
nova wren
#

Do you mean to add UsersService to the AppModule's context?

small hare
#

this is app module

@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: '.env',
      isGlobal: true,
    }),
    TypeOrmModule.forRoot({
      type: 'postgres',
      host: process.env.POSTGRES_HOST,
      username: process.env.POSTGRES_USER,
      port: process.env.POSTGRES_PORT,
      ssl: true,
      password: process.env.POSTGRES_PASSWORD,
      database: process.env.POSTGRES_DATABASE,
      synchronize: true,
      entities: [User, Verification],
    }),
    UsersModule,
  ],
  controllers: [AppController, UsersController],
  providers: [AppService, UsersService],
})
export class AppModule {}
nova wren
#

Okay, why? Why do you need a new instance of UsersService in AppModule? Do you not have a UsersModule where UsersService is originally instanced?

small hare
nova wren
#

You can probably remove UsersController too 😉

small hare