首页 > 解决方案 > 在网络中的其他设备上查看 NodeJS 项目

问题描述

我正在尝试从其他设备查看 CreateReactApp 项目。我尝试0.0.0.0通过将“start”脚本设置为:

"start": "cross-env HOST=0.0.0.0 react-scripts start".

虽然控制台确实记录了

Attempting to bind to HOST environment variable: 0.0.0.0
If this was unintentional, check that you haven't mistakenly set it in your 
shell.
Learn more here: [URL BLOCKED BY GITHUB].

我无法使用计算机的 IP 从同一网络上的另一台设备访问此项目。

同时,我设法使用计算机的 IP 从同一设备访问同一计算机上的其他项目(从“tomcat”本地服务器)。知道为什么会发生这种情况吗?我的环境:Windows10。我在不止一个 Create-React-App 项目中尝试了“PowerShell”和“Windows 上的 Ubuntu (WSL) 上的 Bash”。

标签: reactjsnpmcreate-react-app

解决方案


默认情况下,Create React App 在localhost:3000. 因此访问<ip address of machine serving the app>:3000应该适用于同一网络中的设备。

还原 package.json 中启动脚本的更改并在其中打开应用程序<ip adress>:3000


推荐阅读