[英]When i run “npm start” on my react project, the network address doesn't work on my phone
I started using React and encountered a little problem. 我开始使用React,遇到一个小问题。 I ran "npx create-react-app first-react" then "cd first-react" and finally "npm start" which started the server.
我先运行“ npx create-react-app first-react”,然后运行“ cd first-react”,最后运行“ npm start”,这启动了服务器。
I am able to use the localhost
in my desktop browser and everything works fine. 我可以在桌面浏览器中使用
localhost
,并且一切正常。 But whenever I try to access the network address on my phone or my other laptop, I get the error: 但是,每当我尝试访问手机或其他笔记本电脑上的网络地址时,都会收到错误消息:
This site can't be reached
无法访问该网站
I am able to view application running in the desktop browser. 我能够查看在桌面浏览器中运行的应用程序。
I am using the following URL to access the app: 我正在使用以下URL访问该应用程序:
Local: http://localhost:3000/
本地: http:// localhost:3000 /
On Network: http://192.168.x.xx:3000/ (this doesn't work on my phone.)
在网络上: http://192.168.x.xx:3000 / (这在我的手机上不起作用。)
I tried running: 我尝试跑步:
HOST=0.0.0.0 npm run start
...but to no avail. ...但无济于事。
I also tried creating the .env
file and adding PORT = 4000
but it does not fix the problem. 我也尝试创建
.env
文件并添加PORT = 4000
但是它不能解决问题。
Not sure what the problem is, but I am still learning so maybe the answer is simple. 不知道是什么问题,但我仍在学习,因此答案很简单。
If you're working on a Windows PC you might need to check your firewall settings. 如果您在Windows PC上工作,则可能需要检查防火墙设置。 Your firewall might be blocking the connection even on the same network.
您的防火墙即使在同一网络上也可能阻止了连接。
Have a look at: How to open a port on windows firewall for instructions on how to open a port. 看看: 如何在Windows防火墙上打开端口,以获取有关如何打开端口的说明。
Good luck with your project 祝您项目顺利
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.