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

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

我做错了什么?


当前回答

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

其他回答

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

react-native运行android

请检查地铁服务器是否正在运行任何其他端口。如果有,停止所有服务器,然后重新启动服务器,再试一次。

(快速回答)

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

此错误是因为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.

在我的例子中,我在模拟器中设置了一个代理。 它在我删除代理后恢复正常。

类似的问题也发生在我身上。 显然Mcafee阻塞了8081端口。我花了好几个小时才弄明白。

尝试运行:

react-native run-android --port=1234

当应用程序在模拟器上显示错误时,进入开发设置(Ctrl+M)。

将“调试服务器主机和设备端口”更改为“localhost:1234”。

关闭应用程序,并从应用程序抽屉启动它。