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

Expo SDK49升级至51后出现npm ERESOLVE依赖冲突求助

问题描述

基于Expo SDK49的React Native应用,因版本弃用升级至SDK51后出现npm依赖冲突错误。Windows系统下使用--legacy-peer-deps、audit fix均无法解决,已尝试移除废弃包、删除node_modules和package-lock.json、调整包版本等操作,问题依旧。

当前package.json配置

{   
"name": "firstreactnativeapp",   
"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-async-storage/async-storage": "1.23.1",     
"@react-navigation/bottom-tabs": "^6.5.10",     
"@react-navigation/native": "^6.1.9",     
"@react-navigation/native-stack": "^6.9.15",     
"@react-spring/native": "^9.5.5",     
"@react-spring/web": "^9.7.3",     
"@types/react": "~18.2.45",     
"expo": "^51.0.8",     
"expo-blur": "~13.0.2",     
"expo-linear-gradient": "~13.0.2",     
"expo-location": "~17.0.1",     
"expo-splash-screen": "~0.27.4",     
"expo-status-bar": "~1.12.1",     
"firebase": "^10.5.2",     
"formik": "^2.4.5",     
"react": "^18.3.1",     
"react-native": "0.74.1",     
"react-native-reanimated": "~3.10.1",     
"react-native-safe-area-context": "4.10.1",     
"react-native-screens": "3.31.1",     
"react-native-vector-icons": "^10.0.0",     
"react-native-webview": "13.8.6",     
"react-tinder-card": "^1.6.4"    },   
"devDependencies": {     
"@babel/core": "^7.20.0",     
"typescript": "^5.3.3"   },   
"private": true 
} 

错误信息核心内容

npm ERR! code ERESOLVE 
npm ERR! ERESOLVE could not resolve 
npm ERR! 
npm ERR! While resolving: react-native@0.74.1 
npm ERR! Found: react@18.3.1 
npm ERR! Could not resolve dependency: 
npm ERR! peer react@"18.2.0" from react-native@0.74.1 
npm ERR! Conflicting peer dependency: react@18.2.0 

解决方法

1. 修正React版本(核心解决步骤)

react-native 0.74.1(对应Expo SDK51)的peer依赖明确要求react@18.2.0,但当前使用的是react@18.3.1,这是冲突根源。修改package.json的dependencies中react版本:

"react": "18.2.0",

2. 同步类型定义版本(可选但建议)

确保@types/react版本与react主版本兼容,当前~18.2.45与react@18.2.0匹配,无需修改;若后续出现类型错误,可调整为~18.2.0。

3. 清理并重新安装依赖

执行以下命令彻底清理现有依赖并重新安装:

# 删除node_modules和锁文件
rm -rf node_modules package-lock.json
# 重新安装依赖
npm install

若仍存在次要依赖冲突,可尝试添加--legacy-peer-deps参数:

npm install --legacy-peer-deps

4. 排查非官方Expo依赖兼容性

  • react-native-vector-icons:Expo项目建议使用@expo/vector-icons替代,原生react-native-vector-icons可能需要额外配置,可考虑替换以避免兼容性问题。
  • @react-spring/web:若项目不涉及Web端部署,可移除该包,减少不必要的依赖冲突。
  • react-tinder-card:确认该包是否支持react-native 0.74.x版本,若存在兼容性问题,可寻找替代方案或升级到兼容版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 09:35:16