You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

升级至Expo SDK 52时遭遇依赖冲突问题求助

Expo SDK升级时ERESOLVE依赖冲突解决方案

问题场景

原本运行Expo SDK 51,按官方流程执行npm install expo@latest成功升级SDK,但执行npx expo install --fix升级依赖时抛出ERESOLVE错误。核心冲突点为:

  • 项目当前依赖@react-navigation/drawer@6.7.2
  • 升级后的expo-router@4.0.7要求可选peer依赖@react-navigation/drawer@^7.0.0,版本不匹配导致依赖解析失败。

错误日志如下:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: expo-router@4.0.7
npm ERR! Found: @react-navigation/drawer@6.7.2
npm ERR! node_modules/@react-navigation/drawer
npm ERR!   @react-navigation/drawer@"^6.7.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @react-navigation/drawer@"^7.0.0" from expo-router@4.0.7
npm ERR! node_modules/expo-router
npm ERR!   expo-router@"~4.0.7" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @react-navigation/drawer@7.0.6
npm ERR! node_modules/@react-navigation/drawer
npm ERR!   peerOptional @react-navigation/drawer@"^7.0.0" from expo-router@4.0.7        
npm ERR!   node_modules/expo-router
npm ERR!     expo-router@"~4.0.7" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! 
npm ERR! For a full report see:
npm ERR! C:\Users\Ismail\AppData\Local\npm-cache\_logs\2024-11-21T04_03_35_490Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Ismail\AppData\Local\npm-cache\_logs\2024-11-21T04_03_35_490Z-debug-0.log
Error: npm install exited with non-zero code: 1

项目原package.json内容:

{
  "name": "m24",
  "version": "1.0.0",
  "main": "expo-router/entry",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@gorhom/bottom-sheet": "^5.0.2",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-navigation/drawer": "^6.7.2",
    "@reduxjs/toolkit": "^2.2.8",
    "axios": "^1.7.7",
    "expo": "~51.0.39",
    "expo-constants": "~17.0.3",
    "expo-document-picker": "~13.0.1",
    "expo-linking": "~7.0.3",
    "expo-localization": "~16.0.0",
    "expo-router": "~4.0.7",
    "expo-secure-store": "~14.0.0",
    "expo-status-bar": "~2.0.0",
    "nativewind": "^2.0.11",
    "react": "18.3.1",
    "react-native": "0.76.2",
    "react-native-element-dropdown": "^2.12.1",
    "react-native-gesture-handler": "~2.20.2",
    "react-native-reanimated": "~3.16.1",
    "react-native-safe-area-context": "4.12.0",
    "react-native-screens": "~4.1.0",
    "react-redux": "^9.1.2",
    "swr": "^2.2.5"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "tailwindcss": "^3.3.2"
  },
  "private": true
}

解决方案

1. 升级冲突依赖到兼容版本

直接升级@react-navigation/drawer到expo-router要求的^7.0.0版本,执行命令:

npm install @react-navigation/drawer@^7.0.0

完成后重新执行依赖修复命令:

npx expo install --fix

2. 手动修改package.json后重装

直接编辑package.json,将@react-navigation/drawer的版本改为^7.0.0,保存后执行:

npm install

修改后的依赖片段示例:

"@react-navigation/drawer": "^7.0.0",

3. 临时跳过peer依赖检查(应急方案)

若暂时无法升级依赖,可使用--legacy-peer-deps参数跳过冲突检查,但可能存在潜在兼容性问题,执行:

npx expo install --fix --legacy-peer-deps

4. 清理缓存后重试

若上述方法无效,清理npm缓存后重新安装:

npm cache clean --force
rm -rf node_modules package-lock.json
npm install
npx expo install --fix

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

火山引擎 最新活动