我正在尝试使用以下命令运行react native应用程序。
npm run android
我收到以下错误。
即时通讯使用nvm - nvm use stable
现在使用节点v8.9.4(npm v4.6.1)
**package.json**
{
"name": "client",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.11.0",
"jest-expo": "23.0.0",
"react-test-renderer": "16.0.0"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^23.0.4",
"react": "16.0.0",
"react-native": "0.50.3"
}
}
另一个解决方案建议重新运行构建过程,因为可能存在一些干扰,但这对我不起作用。
答案 0 :(得分:6)
我设法解决了这个问题。错误消息显示0.50.3
的反应原生版本。
但最新版本为0.52
,可在此处查看https://facebook.github.io/react-native/versions.html。
所以我更新了包json以反映这一点。
"dependencies": {
"react-native": "0.52"
}
然后我删除了npm模块并重新npm install
。这解决了我的问题。
tldr;更新package.json react-native依赖项以反映最新版本。
答案 1 :(得分:1)
我有同样的问题,而KHAN给了我们正确的解决方案。
我在这里把package.json放在需要修复的那些人身上:
{
"name": "project",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-native-scripts": "1.11.0",
"jest-expo": "25.0.0",
"react-test-renderer": "16.0.0"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "node node_modules/jest/bin/jest.js --watch"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"expo": "^25.0.0",
"react": "16.0.0",
"react-native": "0.52"
}
}