CodePark/ questions / Database integration (TypeORM / Prisma)
START PRACTICINGPRACTICE
Backend question · NestJS › Database integration (TypeORM / Prisma)

UsersService injects @InjectRepository(User), but UsersModule has no TypeOrmModule.forFeature([User]) in its imports. What happens?

Nest throws at startup that it can't resolve the UserRepository dependency

Nest 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.