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

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

我做错了什么?


当前回答

在我的例子中,我只是关闭了app form模拟器 然后再运行一次

react-native运行android

其他回答

默认情况下,一个名为“Metro server”的小型JavaScript服务器运行在端口8081上。

您需要使此端口可用于此服务器启动。所以,

释放端口 关闭虚拟设备 “react-native run-android”。

如何释放端口?

http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html

如何在windows中杀死当前使用本地主机端口的进程?

最重要的是,我从8升级了我的节点版本。X到10.x(最新),正如facebook建议的那样 @ https://facebook.github.io/react-native/docs/getting-started

嘿,伙计们,两个按钮的组合解决了我的问题。这与港口有关。

adb reverse tcp:8088 tcp:8088
react-native run-android --port=8088

通过这样做,应用程序可以通过USB连接我的手机。 我认为我的AV或Vagrant或PC中的其他东西正在使用该端口。

如果需要,您可以将8088更改为其他内容。

享受吧!

(快速回答)

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

此错误是因为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 js降级到小于12的版本,然后删除nodemodule,然后再次运行NPM install

关闭代理,如果你在android studio设置代理,默认使用代理