You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NestJS新建组件依赖注入报错,运行时出现502网关错误

NestJS 502 Bad Gateway 及依赖注入错误排查

项目运行时抛出502 Bad Gateway错误,注释app.module.ts中相关模块后代码可正常运行。该模块仅通过数据仓库连接数据库,核心代码如下:

模块导入部分

imports : [
  TypeOrmModule.forFeature([KYCStatus, User, Country], 'customerDB'),
]

服务构造函数

@InjectDataSource('customerDB')
private readonly dataSource: DataSource,

使用DataSource获取仓库

const countryRepository = this.dataSource.getRepository(Country);

抛出的错误信息

Error: Nest can't resolve dependencies of the customerDB_KYCStatusRepository (?). Please make sure that the argument customerDBDataSource at index [0] is available in the TypeOrmModule context.

排查方向

  • 确认TypeOrmModule是NestJS的有效模块
  • 检查customerDBDataSource这个提供者是否属于当前TypeOrmModule上下文
  • 如果customerDBDataSource是从独立模块导出的,需确认该模块已在TypeOrmModule中导入,示例结构:
@Module({
  imports: [ /* 包含customerDBDataSource的模块 */ ]
})

内容的提问来源于stack exchange,提问作者Rohit Mittal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 16:09:59