npx react native更新后运行android错误



我已经升级了我的react本机并创建了一个新项目。

当我运行npx反应原生运行android iam得到以下错误。

D: \React Native Playground\AwesomeProject\node_modules\areact Native\cli.js{"root":"D:\React Nature Playground\AowesomeProject","reactActivitPath":"D:\React Native Playground\AwosomeProject\node_modules\React Native","dependencies":{},"命令":[{"name":"log ios","description":"启动ios设备syslog tail"},{"name="run ios","description":"构建您的应用程序并在ios模拟器上启动它","examples":[{"desc":"在不同的模拟器上运行,例如iPhone 5","cmd":"react native run ios--simulator \"iPhone 5\"},{"desc":"传递iOS目录的非标准位置","cmd":"react native run iOS--project path\"/app/ios\"},{"desc":"在连接的设备上运行,例如Max的iPhone","cmd":"react native Run ios--device\"Max的iPhone"},{,"options":[{"name":"--simulator[string]","description":"显式设置要使用的模拟器。(可选)在末尾的括号中包括iOS版本,以匹配确切的版本:\"iPhone 6(10.0)\","default":"iPhone 11"},{"name":"--configuration[string]","description":"显式设置要使用的方案配置","default":"Debug"},{"name":"--projectpath[string]","description":"相对于Xcode项目(.xcodeproj)所在的项目根的路径。","default":"ios"},{"name:"--device[string]","description":"显式设置设备按名称使用。如果连接了单个设备,则不需要该值。"},{"name":"--udid[string]","description":"明确设置设备以供udid使用"},{"name":"--无打包程序","description":"在构建时不要启动打包程序"},{"name":"--port[number]","default":8081},{"name:"--terminal[string]","description":"使用指定的终端路径在新窗口中启动Metro Bundler。"}]},}"name":"log android","description":"starts logkitty"},{"name":"run android","description":"构建您的应用程序并在连接的android模拟器或设备上启动它","options":[{"name":"--root[string]","description":"覆盖android构建的根目录(包含android目录)","default":"},{"name":"--variable[string]","description":"指定应用程序的内部版本变体","default":"debug"},{"name:"--appFolder[string]","description":"为android源指定不同的应用程序文件夹名称。如果不是,我们假设为\"app\","default:"app"},{"name":"--appId[string]","description":"指定要在生成后启动的应用程序Id。","default":"},{"name:"--appIdSuffix[string]","description":"指定要在生成后启动的applicationIdSuffix。","default":"},{"name":"--main activity[string]","description":"要启动的活动名称","default":"MainActivity"},{,{"name":"--no packager","description":"生成时不要启动打包程序"},{"name":"-port[number]","default":8081},{"name":"--terminal[string]","description":"使用指定的终端路径在新窗口中启动Metro Bundler。"},{"name":"--tasks[list]","description":"运行自定义Gradle任务。默认情况下,它是\"installDebug\"},{"name":"--no jetifier","description":"不要运行\"jetizer"–AndroidX转换工具。默认情况,它在Gradle之前运行,以方便处理还不支持AndroidX的库。请参阅:https://www.npmjs.com/package/jetifier.","default":false}]}],"assets":[],"platforms":{"ios":{},"android":{}},"hast^

失败:生成失败,出现异常。

  • 其中:脚本"D:\React Native Playground\AwesomeProject"\node_modules@react-native-community\cli平台android\native_modules.gradle'行:200

  • 哪里出了问题:评估脚本时出现问题。

    无法解析React Native CLI配置。应运行"D:\react native Playground\AwesomeProject"目录中的"npx.cmd--quiet--no install react native config"命令以输出有效的JSON,但它没有。这可能是由于npx解析为遗留的全局react本机二进制文件造成的。请确保卸载任何全局"react native"二进制文件:"npm uninstall-g react native-rect native cli",然后重试。

My package.json
{
"name": "AwesomeProject",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"react": "16.9.0",
"react-native": "0.61.5"
},
"devDependencies": {
"@babel/core": "7.8.4",
"@babel/runtime": "7.8.4",
"@react-native-community/eslint-config": "0.0.5",
"babel-jest": "24.9.0",
"eslint": "6.8.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.56.4",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
} 

根据错误消息,听起来npx可能正在解析为遗留的react本地二进制文件。如果您以前安装过react native cli,这很可能是罪魁祸首,因为cli现在与react native-binary一起包含。Per-rect原生文档:

如果您以前安装了全局react本机cli包,请将其删除,因为它可能会导致意外问题。

如果您还没有,请尝试卸载带有npm的react native和react nativecli,然后使用npx(随node一起提供)以供将来使用。

npm uninstall -g react-native react-native-cli

然后,

npx react-native init AwesomeProject

最新更新