React-native run-android命令通过在android模拟器中留下消息来终止。信息如下:

无法加载脚本。确保你要么运行Metro服务器,要么运行你的捆绑包index.android。Bundle '被正确地打包以便发布。

我做错了什么?


当前回答

(快速回答)

在我的工作空间尝试解决这个问题后,我找到了一个解决方案。

此错误是因为Metro使用NPM和Node版本的某些组合时出现了问题。

你有两个选择:

Alternative 1: Try to update or downgrade npm and node version. Alternative 2: Go to this file: \node_modules\metro-config\src\defaults\blacklist.js and change this code: var sharedBlacklist = [ /node_modules[/\\]react[/\\]dist[/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; and change to this: var sharedBlacklist = [ /node_modules[\/\\]react[\/\\]dist[\/\\].*/, /website\/node_modules\/.*/, /heapCapture\/bundle\.js/, /.*\/__tests__\/.*/ ]; Please note that if you run an npm install or a yarn install you need to change the code again.

其他回答

只需添加三个飞溅: node_modules \ metro-config \ src \ \ blacklist.js违约

更换此部件:

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

在地铁黑名单中更新此部分

var sharedBlacklist = [
  /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
  /website\/node_modules\/.*/,
  /heapCapture\/bundle\.js/,
  /.*\/__tests__\/.*/
];

这适用于我,另外添加端口号和运行android

npx react-native run-android --port=8082 (maybe port number differs)

首先执行步骤4和5,然后可以运行项目。如果您没有得到结果(步骤4和5),请执行以下步骤

1-尝试降级你的Node版本(当前版本是12.13.1)

  choco uninstall nodejs
  choco install nodejs --version 12.8

2-添加npm模块的路径(C:\Users\your user name\AppData\Roaming\npm)到系统变量而不是用户变量

3-使用命令全局安装react native

  npm install -g react-native-cli

4-进入项目目录的根目录,执行以下命令:

  react-native start

5-打开项目根目录下的另一个终端,执行以下命令:

   react-native run-android 

编辑:

你在用Genymotion ?是,执行以下步骤。

在以上步骤后,如果您得到以下错误?

error Failed to launch emulator. Reason: No emulators found as an output of `emulator -list-avds`.

打开你的genymotion,转到:

genymotion菜单->设置-> ADB ->然后选择使用自定义android sdk工具(点击浏览找到sdk位置)

最后,再次运行您的项目。

这也可能是由于在清单中禁用INTERNET权限造成的。我有一个不需要/使用任何互联网的应用程序,我已经删除了它。自从我更新这个应用程序已经有一段时间了,我已经完全忘记了它。花了大约一个小时把每个答案都试了一遍。