简体   繁体   English

React Native未在本地主机上运行

[英]React native not running on localhost

React native stopped working, whenever I run it now (no matter which project) I get the error could not connect to development server | React Native停止工作,无论何时运行(无论哪个项目),我都收到错误,无法连接到开发服务器| ensure the following node server is running and available on the same network - run npm start from react native root. 确保以下节点服务器正在同一网络上运行并可用-从反应本机根目录运行npm start。

Node server url is correctly set in appdelegate 在appdelegate中正确设置了节点服务器URL

URL : http://localhost:8081/index.ios.bundle ? 网址: http:// localhost:8081 / index.ios.bundle platform=ios&dev=false 平台= iOS和开发= FALSE

I usually just run npm start in my terminal. 我通常只是在终端上运行npm start。 (OSX) I assume it would be the same on Windows (OSX)我认为在Windows上也一样

npm start 

To debug on a real device: 要在真实设备上调试:

  1. On iOS - open the file AppDelegate.m and change localhost to the IP address of your computer. 在iOS上-打开文件AppDelegate.m,然后将localhost更改为计算机的IP地址。 Shake the device to open the development menu with the option to start debugging. 摇动设备以打开开发菜单,并带有开始调试的选项。

     let jsCodeLocation = NSURL(string: "http://{{YOUR IP ADRESS}}:8081/index.bundle?platform=ios") 
  2. On Android, you can open dev menu on the device and select Dev Settings, then update Debug server host for device setting to the IP address of your computer. 在Android上,您可以打开设备上的dev菜单,然后选择开发设置,然后将设备设置的调试服务器主机更新为计算机的IP地址。

Please ensure you have done the following 请确保您已完成以下操作

1) run server using 1)使用运行服务器

npm start

2) if you are using actual device , make sure you are connected to same network 2)如果您使用的是实际设备,请确保您已连接到同一网络

3) for android: run the following command and try again 3)对于android:运行以下命令,然后重试

adb reverse tcp:8081 tcp:8081

I was face same problem while running in physical device. 在物理设备上运行时,我遇到了同样的问题。

I did as below: 我做了如下:

  1. Open terminal and check your local ip address. 打开终端并检查您的本地IP地址。
  2. Shake device(android) click on dev settings 摇动设备(Android),点击开发设置
  3. Click "Debug server host & port for device" under debugging 在调试下单击“调试设备的服务器主机和端口”
  4. type local ip address and port number. 输入本地IP地址和端口号。

note: cross check in browser ip along with port number. 注意:交叉检查浏览器ip和端口号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM