升级Expo SDK 51后npm install失败,依赖冲突求助
解决Expo SDK51下@expo/webpack-config依赖冲突问题
问题背景
迁移至Expo SDK51后,本地执行npm install及EAS build的安装阶段均失败,核心原因是@expo/webpack-config与expo存在版本依赖冲突。
当前package.json配置
{ "dependencies": { "@expo/webpack-config": "^19.0.1", "@react-native-async-storage/async-storage": "1.23.1", "@react-native-community/slider": "4.5.2", "@react-native-firebase/app": "^18.9.3", "@react-native-firebase/auth": "^18.9.3", "@react-native-picker/picker": "2.7.5", "@react-navigation/bottom-tabs": "^6.5.11", "@react-navigation/native": "^6.1.9", "@react-navigation/native-stack": "^6.9.17", "@testing-library/react": "^14.2.1", "axios": "^1.6.5", "bad-words": "^3.0.4", "base-64": "^1.0.0", "date-fns": "^3.3.1", "dotenv": "^16.3.1", "expo": "^51.0.8", "expo-app-loading": "^2.1.1", "expo-dev-client": "~4.0.14", "expo-device": "~6.0.2", "expo-image-picker": "~15.0.5", "expo-linking": "~6.3.1", "expo-notifications": "~0.28.3", "expo-splash-screen": "~0.27.4", "expo-status-bar": "~1.12.1", "firebase": "^10.7.1", "google-auth-library": "^9.4.1", "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.74.1", "react-native-chart-kit": "^6.12.0", "react-native-charts-wrapper": "^0.6.0", "react-native-gesture-handler": "~2.16.1", "react-native-image-picker": "^7.1.0", "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-material-dropdown": "^0.11.1", "react-native-modal": "^13.0.1", "react-native-numeric-input": "^1.9.1", "react-native-paper": "^5.8.0", "react-native-restart": "^0.0.27", "react-native-safe-area-context": "4.10.1", "react-native-screens": "3.31.1", "react-native-svg": "15.2.0", "react-native-web": "~0.19.10", "react-router-native": "^6.21.1", "request": "^2.88.2" }, "devDependencies": { "@babel/core": "^7.24.5", "@babel/eslint-parser": "^7.23.3", "@babel/preset-env": "^7.24.5", "@babel/preset-react": "^7.24.1", "@testing-library/jest-native": "^5.4.3", "@testing-library/react-native": "^12.4.3", "metro-react-native-babel-preset": "^0.66.2", "babel-jest": "^29.7.0", "detox": "^20.18.1", "eslint": "^8.56.0", "eslint-plugin-jest": "^27.6.3", "eslint-plugin-react": "^7.33.2", "eslint-plugin-react-native": "^4.1.0", "jest": "^29.7.0", "jest-expo": "~51.0.2", "react-test-renderer": "^18.2.0", "ts-jest": "^29.1.2" } }
错误日志
npm error code ERESOLVE npm error ERESOLVE could not resolve npm error npm error While resolving: @expo/webpack-config@19.0.1 npm error Found: expo@51.0.8 npm error node_modules/expo npm error expo@"^51.0.8" from the root project npm error peer expo@"*" from expo-splash-screen@0.17.5 npm error node_modules/expo-app-loading/node_modules/expo-splash-screen npm error expo-splash-screen@"~0.17.0" from expo-app-loading@2.1.1 npm error node_modules/expo-app-loading npm error expo-app-loading@"^2.1.1" from the root project npm error 18 more (expo-application, expo-asset, expo-constants, ...) npm error npm error Could not resolve dependency: npm error peer expo@"^49.0.7 || ^50.0.0-0" from @expo/webpack-config@19.0.1 npm error node_modules/@expo/webpack-config npm error @expo/webpack-config@"^19.0.1" from the root project npm error npm error Conflicting peer dependency: expo@50.0.18 npm error node_modules/expo npm error peer expo@"^49.0.7 || ^50.0.0-0" from @expo/webpack-config@19.0.1 npm error node_modules/@expo/webpack-config npm error @expo/webpack-config@"^19.0.1" from the root project npm error npm error Fix the upstream dependency conflict, or retry npm error this command with --force or --legacy-peer-deps npm error to accept an incorrect (and potentially broken) dependency resolution.
解决方案
1. 升级@expo/webpack-config至适配SDK51的版本
@expo/webpack-config@19.0.1仅支持Expo SDK49和SDK50,SDK51需要使用^20.0.0版本。修改package.json中的对应依赖:
"@expo/webpack-config": "^20.0.0"
修改后执行:
npm install
2. 清理缓存并重新安装(若升级后仍有问题)
执行以下命令彻底清理依赖缓存后重新安装:
npm cache clean --force rm -rf node_modules package-lock.json npm install
3. 移除废弃依赖(可选)
expo-app-loading已在SDK48+被废弃,官方推荐直接使用expo-splash-screen的API替代。移除该依赖可避免额外的版本冲突:
npm uninstall expo-app-loading
之后需调整代码,改用expo-splash-screen的相关方法处理启动屏逻辑。
内容的提问来源于stack exchange,提问作者walterairs
相关产品推荐
相关产品推荐

