nest 中正确使用 typeorm
问题:
在 nest 中使用 typeorm 时遇到“nest can't resolve dependencies of the bookservice”错误,请求帮助。
代码片段:
// app.module.ts @Module({ imports: [ TypeOrmModule.forRoot({ /* ... */ }), BookModule, ], controllers: [BookController], providers: [BookService], }) export class AppModule {} // book.module.ts @Module({ imports: [TypeOrmModule.forFeature([BookEntity])], controllers: [BookController], providers: [BookService], exports: [BookService] }) export class BookModule {}
解答:
nest 无法解析 bookservice 的依赖,因为 bookentityrepository 在 appmodule 上下文中不可用。
推荐的解决方案是:
以上就是Nest 中 TypeORM 依赖解析错误:为什么 BookService 会报错“Nest can't resolve dependencies”?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号