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

运行NestJS GraphQL服务时出现Package subpath './express4'未定义错误

解决方案

问题根源

你的依赖存在版本冲突:

  • @nestjs/apollo@11.0.6 仅兼容 Apollo Server 4.x,但你安装了 @apollo/server@^5.0.0(5.x版本),两者不兼容
  • 同时存在已废弃的 apollo-server-express@^3.13.0,它与 @apollo/server@5.x 会产生依赖冲突,导致找不到./express4子路径

具体修复步骤

  1. 修改package.json依赖
    删除apollo-server-express,并将@apollo/server降级到4.x兼容版本,修改后的dependencies如下:

    "dependencies": {
      "@apollo/server": "^4.10.0",
      "@nestjs/apollo": "11.0.6",
      "@nestjs/common": "^11.0.1",
      "@nestjs/core": "^11.0.1",
      "@nestjs/graphql": "11.0.6",
      "@nestjs/platform-express": "^11.0.1",
      "graphql": "^16.11.0",
      "reflect-metadata": "^0.2.2",
      "rxjs": "^7.8.1"
    }
    
  2. 清理并重新安装依赖
    执行以下命令:

    rm -rf node_modules package-lock.json
    npm install
    
  3. 验证配置
    你的app.module.ts配置是正确的,无需修改。启动服务后即可正常运行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 07:12:48