本文介绍了反应本机更改侦听端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react native android 并且在将应用程序部署到 android 设备上时遇到了问题.当我跑

I am using react native android and having face issues to deploy the app on an android device.When I run

react-native 启动,它不会在端口 8081

我尝试了以下提到的几个选项:

I have tried a few options mentioned at:

  1. https://facebook.github.io/react-native/docs/troubleshooting.html

试图停止在端口号 8081 上运行的进程,但没有成功

Tried to stop the process running at port number 8081, but no success

我的问题是,我们可以将 React Native 开发服务器端口从 8081(这是 android 中的默认值,但我们可以在 ios 中从 AppDelegate.m 文件中更改)更改为其他内容或任何其他方法

My question is that can we change the React Native dev server port from 8081 (which is a default in android however the same we can change in ios from AppDelegate.m file) to something else or any other approach

非常感谢您的回复.谢谢

Your responses will be highly appreciated. Thanks

推荐答案

不确定是否记录在案[1],您可以通过 CLI 参数指定端口,如下所示:

Not sure if this is documented or not[1], you can specify the port via a CLI argument, like this:

react-native start --port 9988

我在源代码中找到了它,它在我的本地机器上运行:)

I found it in the source code, and it worked on my local machine :)

https://github.com/facebook/react-native/blob/master/local-cli/server/server.js#L30

[1] 现在记录在这里:https://facebook.github.io/react-native/docs/troubleshooting#using-a-port-other-than-8081

[1] This is now documented here: https://facebook.github.io/react-native/docs/troubleshooting#using-a-port-other-than-8081

这篇关于反应本机更改侦听端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:47