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

NestJS从9升级到10后调用CacheModule.registerAsync报错求助

解决方案:NestJS 10升级后CacheModule.registerAsync报错

核心原因

@nestjs/cache-manager v10版本开始,CacheModule从默认导出改为了命名导出,如果仍使用旧的默认导入方式,会导致CacheModule为undefined,从而触发Cannot read properties of undefined (reading 'registerAsync')错误。

具体修复步骤

  • 修正导入方式
    把原来的默认导入:

    import CacheModule from '@nestjs/cache-manager';
    

    改成命名导入:

    import { CacheModule } from '@nestjs/cache-manager';
    
  • 确保版本匹配
    检查package.json中NestJS核心包(如@nestjs/core、@nestjs/common)和@nestjs/cache-manager的版本均为10.x,避免跨版本兼容问题。示例:

    {
      "@nestjs/core": "^10.3.0",
      "@nestjs/cache-manager": "^10.0.0"
    }
    
  • 清理依赖缓存重新安装
    如果导入方式正确但仍报错,可能是依赖缓存问题:

    1. 执行命令清除npm缓存:npm cache clean --force
    2. 删除node_modules文件夹和package-lock.json文件
    3. 重新安装依赖:npm install
  • 检查代码拼写
    确认调用CacheModule.registerAsync()时没有拼写错误,比如大小写错误、变量名混淆等。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 21:44:51