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

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

我做错了什么?


当前回答

默认情况下,一个名为“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

其他回答

重要, 您的环境中可能有许多Virtual设备。如果您正在更改AVD,请确保再次重复设置。

调试信息,

如果您遇到上述错误,您必须首先验证端口8081上正在运行什么

最快的方法是在终端中使用以下命令

netstat -aon | findstr 8081

如果显示了什么,就意味着端口被阻塞了。如果可能的话,解除那个端口的封锁。

否则,您将需要更改端口。Naveen Kumar在上面的评论中已经提到了这个过程

react-native run-android --port=9001

确保9001也没有被使用:)

(快速回答)

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

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

试试下面的方法。

删除Android和IOS文件夹 运行react-native eject 运行react-native Run -android

也许在前面的步骤之后,你执行了npm start -——reset-cache

我有工作,希望能帮到你。

以下是我在不改变构建的情况下解决这个问题的方法:

1-关闭虚拟设备

2-在物理设备上测试-(它工作)

3-创建新的虚拟设备API 30 Android 10+

4-在新创建的虚拟设备上再次尝试,所有工作都像一个魅力。

在某些情况下,您可能需要关闭React-native捆绑器的端口 用相同的进程重新运行应用程序

1.sudo kill -9 $(sudo lsof -t -i:9001)

2.npm start inside the project

3. react-native run-android