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

如何解决NestJS启动时@nestjs/typeorm报retryAttempts未定义错误

修复NestJS @nestjs/typeorm 报错 Cannot read property 'retryAttempts' of undefined

错误根因

当前使用的@nestjs/typeorm@7.1.5和typeorm@0.2.34版本不兼容:typeorm在0.2.34版本调整了内部连接配置的结构,旧版@nestjs/typeorm读取配置时找不到对应字段,触发报错。

修复方案

  • 方案1:降级typeorm到兼容版本
    @nestjs/typeorm@7.x最高适配typeorm@0.2.33,直接执行以下命令降级即可:
    # npm
    npm install typeorm@0.2.33
    # yarn
    yarn add typeorm@0.2.33
    
  • 方案2:升级@nestjs/typeorm到适配版本
    若需保留typeorm高版本特性,可将@nestjs/typeorm升级到8.x及以上版本,注意需和项目的NestJS核心依赖版本保持匹配:
    # npm
    npm install @nestjs/typeorm@^8.0.0
    # yarn
    yarn add @nestjs/typeorm@^8.0.0
    
  • 配置校验
    检查项目中TypeOrmModule.forRoot()、TypeOrmModule.forRootAsync()的传入配置,确认配置对象不是undefined,且包含必填的连接参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 04:54:03