我正在将我的React Native应用程序从0.59升级到0.61。我所做的就是从react-native init emps_fe6
中的每个模块中yarn add
和package.json
开始重新生成一个全新的项目。另外,将组件复制并App.js
复制到新项目。这是我的新package.json
文件:
{
"name": "emps_fe6",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"@react-native-community/async-storage": "^1.6.2",
"moment": "^2.24.0",
"react": "16.9.0",
"react-native": "0.61.1",
"react-native-cli": "^2.0.1",
"react-native-confirmation-code-field": "^3.9.0",
"react-native-device-info": "^3.1.4",
"react-native-elements": "^1.2.3",
"react-native-gesture-handler": "^1.4.1",
"react-native-gifted-chat": "^0.10.1",
"react-native-keychain": "^4.0.1",
"react-native-linear-gradient": "^2.5.6",
"react-native-modal": "^11.4.0",
"react-native-modal-datetime-picker": "^7.6.0",
"react-native-segmented-control-tab": "^3.4.1",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^4.0.10",
"socket.io-client": "2.1.1"
},
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
然后使用react-native run-android
在Android模拟器上启动。它抛出了版本不匹配的错误:
我不太了解导致错误的原因,因为在组件中没有引用版本0.59.9
,而没有复制App.js
。该项目从全新开始,每个模块分别为yarn add
。以前版本中唯一的东西是组件和App.js
。
答案 0 :(得分:1)
也许您的Metro bundler与早期版本的React Native一起运行导致了此问题。因此,面对此问题时,我通常要做的是像npm start --reset-cache
这样启动捆绑程序。确保停止任何地铁捆绑器运行。
如果问题仍然存在,请尝试重新启动计算机。