首页 > 解决方案 > 如何为 Windows 运行 react-native?我有一个问题:npx react-native run-android 错误

问题描述

我想运行 React Native 项目。我已经尝试过这个命令;npx react-native run-android 和。我试图解决所有错误,但仍然无法运行该项目。这是错误输出。

PS C:\Users\batuh\OneDrive\Masaüstü\native\androidApp> npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 903 file(s) to forward-jetify. Using 8 workers...
info Starting JS server...
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
:ReactNative:Unexpected empty result of running '[node, C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli\build\bin.js, config]' command.
:ReactNative:Running '[node, C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli\build\bin.js, config]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 205

* What went wrong:
A problem occurred evaluating script.
node:internal/modules/cjs/loader:927
  throw err;
  ^Error: Cannot find module 'C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli\build\bin.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)  
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {  code: 'MODULE_NOT_FOUND',  requireStack: []}

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
:ReactNative:Unexpected empty result of running '[node, C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli\build\bin.js, config]' command.
:ReactNative:Running '[node, C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli\build\bin.js, config]' command failed.

FAILURE: Build failed with an exception.

Script 'C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli-platform-android\native_modules.gradle' line: 205

* What went wrong:
A problem occurred evaluating script.
node:internal/modules/cjs/loader:927
  throw err;
  ^Error: Cannot find module 'C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli\build\bin.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {  code: 'MODULE_NOT_FOUND',  requi
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

    at makeError (C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\execa\index.js:174:9)
    at C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\execa\index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async runOnAllDevices (C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
    at async Command.handleAction (C:\Users\batuh\OneDrive\Masaüstü\native\androidApp\node_modules\@react-native-community\cli\build\index.js:186:9)
info Run CLI with --verbose flag for more details.

标签: javascriptnode.jsreact-nativeandroid-studioreact-native-android

解决方案


面对同样的问题,我注意到我们的错误的共同点是:

  • UTF-8 字符:ü在项目所在的路径中。 C:\Users\batuh\OneDrive\Masaüstü\native\androidApp>

这意味着它在构建过程中的某个地方没有 utf-8 编码。


解决方案:将您的项目移动到没有这些字符的路径


推荐阅读