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

使用Expo EAS构建Android AAB时遇npm ERESOLVE依赖冲突

解决Expo EAS构建Android AAB时的npm依赖冲突问题

问题根源

构建失败核心是peer依赖版本冲突:

  • react-native-elements@3.4.2要求react-native-safe-area-context@^3.1.9
  • 但项目当前安装的是react-native-safe-area-context@4.4.1,超出了前者的版本范围
  • 本地运行正常是因为你可能在本地使用了--legacy-peer-deps跳过冲突检查,但EAS构建默认不会启用该参数

另外需纠正错误操作:你在package.json中添加的"legacy-peer-deps":"^7.24.2"无效,legacy-peer-deps是npm的命令行参数,并非依赖包,需删除这一项。

可行解决方案

方案1:配置EAS构建时启用--legacy-peer-deps

直接让EAS在构建阶段执行npm安装时跳过peer依赖检查:

  1. 在项目根目录创建或修改eas.json文件
  2. 添加如下构建配置:
{
  "build": {
    "production": {
      "android": {
        "npm": {
          "installCommand": "npm install --legacy-peer-deps"
        }
      }
    },
    "development": {
      "extends": "production"
    }
  }
}
  1. 重新执行构建命令:eas build -p android

方案2:升级react-native-elements到兼容版本

react-native-elements v4及以上版本已支持react-native-safe-area-context@4.x,升级即可解决冲突:

  1. 执行升级命令:
npm install react-native-elements@latest
  1. 清理旧依赖并重新安装:
rm -rf node_modules package-lock.json
npm install
  1. 重新执行构建命令

方案3:降级react-native-safe-area-context到兼容版本

若不想升级react-native-elements,可将react-native-safe-area-context降级到符合要求的3.x版本:

  1. 安装指定版本:
npm install react-native-safe-area-context@3.4.1
  1. 清理并重新安装依赖:
rm -rf node_modules package-lock.json
npm install
  1. 重新执行构建命令

内容的提问来源于stack exchange,提问作者André Cerutti Franciscatto

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 12:15:39