使用EAS构建Android应用时依赖安装阶段报错求助
React Native + Expo构建安卓应用依赖安装失败问题解决
问题场景
刚接触React Native + Expo,执行eas build --profile development --platform android构建安卓应用时,依赖安装环节失败。已尝试清理缓存重建,但npx expo start --dev-client可正常运行。
报错信息
Running "npm install" in the root dir of your repository 2[stderr] npm ERR! code ERESOLVE3[stderr] npm ERR!4[stderr] ERESOLVE could not resolve5[stderr] npm ERR! 6[stderr] npm ERR!7[stderr] While resolving: @react-native-firebase/auth@16.2.08[stderr] npm ERR! Found: @react-native-firebase/app@15.4.09[stderr] npm ERR! node_modules/@react-native-firebase/app10[stderr] npm ERR! @react-native-firebase/app@"~15.4.0" from the root project11[stderr] npm ERR! 12[stderr] npm ERR! Could not resolve dependency:13[stderr] npm ERR! peer @react-native-firebase/app@"16.2.0" from @react-native-firebase/auth@16.2.014[stderr] npm ERR! node_modules/@react-native-firebase/auth15[stderr] npm ERR! @react-native-firebase/auth@"^16.2.0" from the root project16[stderr] npm17[stderr] ERR! 18[stderr] npm ERR! Conflicting peer dependency: @react-native-firebase/app@16.2.019[stderr] npm ERR! node_modules/@react-native-firebase/app20[stderr] npm ERR! peer @react-native-firebase/app@"16.2.0" from @react-native-firebase/auth@16.2.021[stderr] npm ERR! node_modules/@react-native-firebase/auth22[stderr] npm ERR! @react-native-firebase/auth@"^16.2.0" from the root project23[stderr] npm ERR! 24[stderr] npm ERR! Fix the upstream dependency conflict, or retry25[stderr] npm ERR! this command with --force, or --legacy-peer-deps26[stderr] npm ERR! to accept an incorrect (and potentially broken) dependency resolution.27[stderr] npm ERR! 28[stderr] npm ERR! See /home/expo/.npm/eresolve-report.txt for a full report.29[stderr] 30[stderr] npm ERR! A complete log of this run can be found in:31[stderr] npm ERR! /home/expo/.npm/_logs/2022-11-26T18_50_07_398Z-debug-0.log32npm exited with non-zero code: 1
当前package.json内容
{ "name": "wallet", "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web" }, "dependencies": { "@react-native-firebase/app": "~15.4.0", "@react-native-firebase/auth": "^16.2.0", "@react-native-google-signin/google-signin": "^8.0.1", "@react-navigation/bottom-tabs": "^6.4.0", "@react-navigation/drawer": "^6.5.0", "@react-navigation/material-top-tabs": "^6.3.0", "@react-navigation/native": "^6.0.13", "@react-navigation/native-stack": "^6.9.1", "@rneui/base": "^4.0.0-rc.7", "@rneui/themed": "^4.0.0-rc.7", "expo": "~46.0.16", "expo-dev-client": "~1.3.1", "expo-font": "~10.2.0", "expo-linear-gradient": "~11.4.0", "expo-local-authentication": "~12.3.0", "expo-status-bar": "~1.4.0", "formik": "^2.2.9", "moment": "^2.29.4", "react": "18.0.0", "react-native": "0.69.6", "react-native-gesture-handler": "~2.5.0", "react-native-icon-badge": "^1.1.3", "react-native-linear-gradient": "^2.6.2", "react-native-pager-view": "^5.4.24", "react-native-reanimated": "~2.9.1", "react-native-recaptcha-that-works": "^1.3.2", "react-native-safe-area-context": "^4.3.1", "react-native-screens": "~3.15.0", "react-native-tab-view": "^3.3.0", "react-native-webview": "11.23.0", "styled-components": "^5.3.6" }, "devDependencies": { "@babel/core": "^7.12.9" }, "private": true }
解决方案
核心原因
报错明确显示:@react-native-firebase/auth@16.2.0要求的peer依赖是@react-native-firebase/app@16.2.0,但当前项目安装的是@react-native-firebase/app@~15.4.0,版本不匹配导致依赖解析失败。本地开发能运行是因为开发环境对peer依赖冲突的容忍度更高,但EAS构建时严格遵循依赖解析规则。
具体修复步骤
- 统一Firebase依赖版本:将
@react-native-firebase/app和@react-native-firebase/auth调整为相同大版本,二选一即可:
方案一:升级到16.2.0版本
方案二:降级到15.4.0版本"@react-native-firebase/app": "16.2.0", "@react-native-firebase/auth": "16.2.0""@react-native-firebase/app": "~15.4.0", "@react-native-firebase/auth": "~15.4.0" - 重新安装依赖:执行以下命令清理旧依赖并重新安装
rm -rf node_modules package-lock.json npm install - 重新触发构建:再次运行构建命令
eas build --profile development --platform android
临时应急方案(不推荐长期使用)
如果暂时不想调整版本,可以在构建时添加参数跳过peer依赖检查,但可能带来潜在兼容性问题:
eas build --profile development --platform android --npm-args="--legacy-peer-deps"
内容的提问来源于stack exchange,提问作者Sapir
相关产品推荐
相关产品推荐

