#TypeORM how to get repository by InjectRepository() when use TypeOrmModule.forRootAsync()

2 messages · Page 1 of 1 (latest)

lusty galleon
#

i got error by use InjectRepository() decorator.

constructor(
  @InjectRepository(User)
  private readonly userRepository: Repository<User>
) {
}

error:

Nest can't resolve dependencies of the UserSchedule (?). Please make sure that the argument default_UserRepository at index [0] is available in the AppModule context.

module

TypeOrmModule.forRootAsync({
  useFactory: () => {
    entities: [
      "dist/entity/*.js"
    ]
  },
})

how can i get UserRepository by @InjectRepository decorator?

inner dust
#

you can try loading entities using the static glob paths like

TypeOrmModule.forRootAsync({
  useFactory: () => {
    entities: [
      join(__dirname, '**/*.{ts,js}'),
      // join(__dirname, '**/*.entity.{ts,js}')
    ]
  },
})

or set the autoLoadEntities option to true
https://docs.nestjs.com/techniques/database#auto-load-entities