You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native安装新包后构建失败:cli命令执行异常求助

React Native安装新包后Android构建失败问题

错误信息

:ReactNative:Running '[node, D:\wizpeerTourGuideFe wrkbld\wizpeerTourGuideFe\node_modules\@react-native-community\cli\build\bin.js, config]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script 'D:\wizpeerTourGuideFe wrkbld\wizpeerTourGuideFe\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 401

* What went wrong:
A problem occurred evaluating script.
> Process 'command 'node'' finished with non-zero exit value 1   

环境信息

执行npx react-native info输出:

info Fetching system and libraries information...
System:
  OS: Windows 10 10.0.19045
  CPU: (4) x64 Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
  Memory: 9.51 GB / 15.88 GB
Binaries:
  Node:
    version: 18.20.4
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 10.8.3
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | Google APIs Intel x86_64 Atom
      - android-34 | Google Play Intel x86_64 Atom
      - android-35 | Google Play Intel x86_64 Atom
    Android NDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: AI-241.19072.14.2412.12360217
  Visual Studio: Not Found
Languages:
  Java: 17.0.12
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.1
    wanted: 0.74.1
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found ,

package.json配置

{
  "name": "wizpeerTourGuideFe",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-native-community/netinfo": "^11.3.2",
    "axios": "^1.7.0",
    "body-parser": "^1.20.2",
    "date-fns": "^3.6.0",
    "lottie-react-native": "^7.0.0",
    "moment": "^2.30.1",
    "react": "18.2.0",
    "react-native": "0.74.1",
    "react-native-calendars": "^1.1305.0",
    "react-native-chart-kit": "^6.12.0",
    "react-native-compressor": "^1.8.25",
    "react-native-device-info": "^11.1.0",
    "react-native-document-picker": "^9.3.0",
    "react-native-fs": "^2.20.0",
    "react-native-gifted-chat": "^2.4.0",
    "react-native-htmlview": "^0.17.0",
    "react-native-http-bridge-refurbished": "^1.2.9",
    "react-native-image-base64": "^0.1.4",
    "react-native-image-crop-picker": "^0.41.2",
    "react-native-image-picker": "^7.1.2",
    "react-native-keep-awake": "^4.0.0",
    "react-native-network-info": "^5.2.1",
    "react-native-paper": "^5.12.5",
    "react-native-permissions": "^4.1.5",
    "react-native-popup-menu": "^0.16.1",
    "react-native-safe-area-context": "^4.11.1",
    "react-native-share": "^10.2.1",
    "react-native-sqlite-storage": "^6.0.1",
    "react-native-svg": "^15.3.0",
    "react-native-swiper-flatlist": "^3.2.5",
    "react-native-vector-icons": "^10.2.0",
    "react-native-video": "^6.1.2",
    "react-native-view-shot": "^3.8.0",
    "wizpeerTourGuideFe": "file:"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.74.83",
    "@react-native/eslint-config": "0.74.83",
    "@react-native/metro-config": "0.74.83",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0"
  },
  "engines": {
    "node": ">=18"
  }
}

已尝试的解决方案

  • 删除node_modules和package-lock.json后重新执行npm install
  • 在android目录执行gradlew clean
  • 切换Node.js版本(18.x和20.x之间来回切换)
  • 强制安装@react-native-community/cli无效

解决建议

1. 移除无效本地依赖

package.json的dependencies中存在"wizpeerTourGuideFe": "file:",这是一个无效的本地依赖路径,会导致npm安装异常,直接删除该条目。

2. 清理缓存并重新安装依赖

Windows命令行执行:

npm cache clean --force
rd /s /q node_modules
del package-lock.json
npm install

Linux/macOS终端执行:

npm cache clean --force
rm -rf node_modules package-lock.json
npm install

3. 安装匹配版本的@react-native-community/cli

React Native 0.74.1需要对应版本的cli,执行以下命令安装兼容版本:

npm install --save-dev @react-native-community/cli@13.6.9

4. 降级npm到兼容版本

RN 0.74.x推荐使用npm 9.x,当前npm版本10.8.3可能存在兼容性问题,执行命令降级:

npm install -g npm@9.8.1

5. 调整Gradle内存配置

进入android目录,打开gradle.properties文件,添加或修改以下配置,增加Gradle的内存分配:

org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m

6. 验证cli命令是否正常执行

在项目根目录直接执行cli的config命令,查看具体错误:

node node_modules/@react-native-community/cli/build/bin.js config

如果该命令报错,根据输出的具体错误信息针对性修复(如缺少依赖、权限问题等)。

内容的提问来源于stack exchange,提问作者B M Ganesh Channakrishnam Shar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 05:09:52