Nest throws at startup that it can't resolve the
UserRepository dependencyNest throws at startup because it can't resolve the repository. forFeature() creates the repository providers, and only in the module that imports it. Without it, UsersModule has no UserRepository, so bootstrap fails.
"The repository works because TypeOrmModule.forRoot() is in AppModule" is wrong. forRoot() only sets up the database connection. It doesn't create repositories. "TypeORM creates the repository lazily on the first query" is also wrong: nothing is created lazily.
Read more
- Database (https://docs.nestjs.com/techniques/database)docs.nestjs.com