如何解决Expo React Native项目中的版本不匹配错误
解决Expo项目版本不匹配问题的步骤
我来帮你排查这个头疼的版本冲突问题——虽然你已经卸载了moment,但这类问题通常是依赖缓存残留或者锁定文件里的冲突信息导致的,试试下面这些具体操作:
1. 彻底清理依赖缓存与残留文件
首先要把所有可能的冲突文件和缓存清干净,这是解决这类问题的核心步骤:
- 删除本地的
node_modules文件夹:rm -rf node_modules # macOS/Linux用户 # Windows用户执行这个 rmdir /s /q node_modules - 删除依赖锁定文件(根据你常用的包管理器选一个):
rm package-lock.json # npm用户 rm yarn.lock # Yarn用户 - 清理包管理器的全局缓存:
npm cache clean --force # npm用户 yarn cache clean # Yarn用户
2. 重新安装依赖
清理完成后,重新安装所有项目依赖:
npm install # npm用户 # 或者Yarn用户执行 yarn install
3. 强制清除Expo缓存并启动项目
最后用Expo的强制清理缓存命令启动项目,确保Expo端的缓存也被重置:
expo start -c
额外建议:替代moment的兼容方案
如果之后你还需要日期处理工具,推荐用date-fns或者Expo官方的expo-date-picker,它们和Expo项目的兼容性更好,不容易触发版本冲突问题。
你的项目配置参考
package.json
{ "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", "eject": "expo eject" }, "dependencies": { "@react-native-community/async-storage": "~1.11.0", "@react-native-community/datetimepicker": "2.4.0", "@react-native-community/masked-view": "0.1.10", "@react-navigation/bottom-tabs": "^5.8.0", "@react-navigation/drawer": "^5.9.0", "@react-navigation/material-top-tabs": "^5.2.16", "@react-navigation/native": "^5.7.3", "@react-navigation/stack": "^5.9.0", "@simdanonline/react-native-rave": "^1.0.5", "axios": "^0.20.0", "expo": "~38.0.8", "expo-auth-session": "~1.4.0", "expo-av": "~8.2.1", "expo-image-picker": "~8.3.0", "expo-status-bar": "^1.0.2", "native-base": "^2.13.14", "react": "~16.13.1", "react-dom": "~16.13.1", "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz", "react-native-elements": "^2.3.0", "react-native-gesture-handler": "~1.6.0", "react-native-reanimated": "~1.9.0", "react-native-safe-area-context": "~3.0.7", "react-native-screens": "~2.9.0", "react-native-tab-view": "^2.15.1", "react-native-web": "~0.13.9", "react-native-webview": "9.4.0" }, "devDependencies": { "@babel/core": "^7.8.6", "babel-preset-expo": "~8.2.3" }, "private": true }
app.json
{ "expo": { "name": "simtwit", "slug": "simtwit", "version": "1.0.0", "orientation": "portrait", "icon": "./assets/icon.png", "splash": { "image": "./assets/splash.png", "resizeMode": "contain", "backgroundColor": "#ffffff" }, "updates": { "fallbackToCacheTimeout": 0 }, "assetBundlePatterns": [ "**/*" ], "ios": { "supportsTablet": true }, "web": { "favicon": "./assets/favicon.png" }, "scheme": "simtwit" } }
环境版本
- npm 6.14.8
- node 12.18.3
- Yarn 1.21.1
内容的提问来源于stack exchange,提问作者Similoluwa Odeyemi
相关产品推荐
相关产品推荐

