Expo远程环境下React Native项目安装时@react-navigation/drawer依赖冲突问题
看起来你在Expo远程开发环境(expo.dev)里安装React Native项目时,碰到了npm依赖冲突的报错,我来帮你梳理下问题根源和可行的解决办法。
问题核心分析
先把报错的关键信息提炼出来,方便你快速定位:
Could not resolve dependency: peer react-native@"0.79.2" from @react-navigation/drawer@7.3.10 Conflicting peer dependency: react-native@0.79.3
简单说就是:你当前项目使用的react-native@0.79.3,和@react-navigation/drawer@7.3.10要求的peer依赖react-native@0.79.2版本不匹配,触发了npm的依赖解析报错。而且这个@react-navigation/drawer是expo-router@5.0.7推荐的依赖版本,进一步加剧了冲突。
针对Expo远程环境的解决办法
因为你是在expo.dev的远程服务器上操作,没法直接在本地控制台执行命令,推荐以下几种适配远程环境的方案:
方案1:在package.json中添加依赖版本覆盖(Overrides)
Expo项目支持通过package.json的overrides字段强制指定依赖版本,让npm忽略peer依赖冲突,直接使用项目已有的React Native版本。你可以修改项目的package.json,添加如下配置:
{ "overrides": { "@react-navigation/drawer": { "react-native": "$react-native" } } }
这个配置会让@react-navigation/drawer强制使用你项目中已安装的react-native@0.79.3,修改完成后重新触发Expo远程环境的依赖安装即可。
方案2:暂时降级React Native到0.79.2
如果使用版本覆盖后仍有问题,可以暂时把项目的react-native版本降级到0.79.2,和@react-navigation/drawer@7.3.10的peer依赖要求对齐。修改package.json中的对应字段:
{ "dependencies": { "react-native": "0.79.2" } }
注:Expo SDK 53原本对应React Native 0.79.3,小版本降级通常不会影响其他Expo插件的兼容性,可以放心尝试。
方案3:升级@react-navigation/drawer到兼容版本
你可以查看@react-navigation/drawer的版本更新记录,找到支持react-native@0.79.3的版本(比如7.3.11及以上版本,具体以官方更新为准),然后修改package.json的依赖配置:
{ "dependencies": { "@react-navigation/drawer": "^7.3.11" } }
如果不确定具体兼容版本,也可以尝试直接指定latest版本安装最新版,通常最新版会同步适配最新的React Native版本。
完整错误日志整理
npm error While resolving: @react-navigation/drawer@7.3.10 npm error Found: react-native@0.79.3 npm error node_modules/react-native npm error react-native@"0.79.3" from the root project npm error peer react-native@"*" from @expo/metro-runtime@5.0.4 npm error node_modules/@expo/metro-runtime npm error peerOptional @expo/metro-runtime@"*" from expo@53.0.10 npm error node_modules/expo npm error expo@"53.0.10" from the root project npm error 27 more (expo-application, expo-asset, expo-blur, expo-constants, ...) npm error @expo/metro-runtime@"5.0.4" from expo-router@5.0.7 npm error node_modules/expo-router npm error expo-router@"~5.0.7" from the root project npm error 35 more (@expo/vector-icons, ...) npm error Could not resolve dependency: npm error peer react-native@"0.79.2" from @react-navigation/drawer@7.3.10 npm error node_modules/@react-navigation/drawer npm error @react-navigation/drawer@"*" from the root project npm error peerOptional @react-navigation/drawer@"^7.3.9" from expo-router@5.0.7 npm error node_modules/expo-router npm error expo-router@"~5.0.7" from the root project npm error Conflicting peer dependency: react-native@0.79.2 npm error node_modules/react-native npm error peer react-native@"0.79.2" from @react-navigation/drawer@7.3.10 npm error node_modules/@react-navigation/drawer npm error @react-navigation/drawer@"*" from the root project npm error peerOptional @react-navigation/drawer@"^7.3.9" from expo-router@5.0.7 npm error node_modules/expo-router npm error expo-router@"~5.0.7" from the root project
内容来源于stack exchange




