简体   繁体   English

当我在react项目上运行“ npm start”时,网络地址在我的手机上不起作用

[英]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.

相关问题 我的反应智能感知在反应运行时不起作用 - My react intellisense doesn't work when react run 我用 create-react-app 创建了一个项目。 在我的 windows 电脑上,但当我尝试在命令行上运行 npm 时,它显示了这个错误。请帮助我 - I created a project with create-react-app. on my windows pc but when is try to run npm start on the command line it shows this error.please help me react-router-dom 不适用于我的项目 - react-router-dom doesn't work for my project 反应路由器 dom 库不适用于我的项目 - react router dom library doesn't work for my project 当我运行“npm run start”时,我的 discord.js 机器人无法启动 - My discord.js bot wont start when I run "npm run start" 为什么我的 vue 应用程序在运行 `npm run serve` 后没有启动? - Why doesn't my vue app start after running `npm run serve`? Webpack - npm 运行启动和构建不起作用? - Webpack - npm run start and build doesn't work? 当我运行 npm 启动时,我的 webpack 找不到我的索引。html 页面 - my webpack cannot find my index.html page when I run npm start 在我的 react js 项目中运行 npm start 时出现白屏 - Getting white screen on running npm start in my react js project 当我为 React Native 项目运行“npm start”命令时没有任何反应 - Nothing happens when I run 'npm start' command for react native project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM