javascript - 如何为 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.
解决方案
面对同样的问题,我注意到我们的错误的共同点是:
- 有UTF-8 字符:
ü
在项目所在的路径中。C:\Users\batuh\OneDrive\Masaüstü\native\androidApp>
这意味着它在构建过程中的某个地方没有 utf-8 编码。
解决方案:将您的项目移动到没有这些字符的路径
推荐阅读
- php - 替换不属于 HTML 标记的任意字符
- java - 尝试使用 if 语句来确定成绩
- functional-programming - Ramda中带有列表头的管道obj键列表
- javascript - 如何使用 Javascript 将 JSON 响应下载到 Excel?
- reactjs - 嵌套的 Suspense 组件会导致顺序加载还是并行加载?
- c# - 允许 RequireUniqueEmail = false 会导致 ChangePasswordAsync 方法出错
- c++ - 为什么我应该在 scanf()-family 成员中加入长度修饰符作为参数?有什么好处?带有长度修饰符的 scanf 有什么作用?
- c - 将项目从 Visual Studio 2008 升级到 2010 后构建 C 项目的问题
- c# - 无法在对象列表中检索类似记录
- python-3.x - 为我的 python 代码获取运行时错误