You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下Create React App启动提示端口被占用的排查求助

问题

用create-react-app搭建的React应用此前运行数月无异常,最近在Windows 10设备上启动时出现报错:Something is already running on port 3000.

已尝试的排查操作

  • 执行 netstat -an 查看输出,未发现3000端口有进程运行
  • 执行 netstat -an | findstr "3000",无输出结果
  • 执行 npx kill-port 3000,之后仍出现端口被占用报错
  • 更换任意应用运行端口,均提示被占用
  • 在资源监视器的“监听端口”列表中未发现3000端口被监听
  • 重启过电脑

目前仅能在Ubuntu 20.04虚拟机中正常运行应用,推测Windows设备存在端口相关问题,寻求更多可行的解决建议。

补充信息

以下是hosts文件(路径:C:\Windows\System32\drivers\etc\hosts)内容:

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
# Added by Docker Desktop
192.168.2.115 host.docker.internal
192.168.2.115 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

可行的解决建议

1. 排查IPv6端口占用

Windows下netstat -an默认仅显示IPv4连接,执行以下命令检查IPv6端口:
netstat -ano -p tcpv6 | findstr "3000"
若找到对应进程,用taskkill /F /PID [进程ID]强制结束。

2. 解决WSL端口转发冲突

如果开启了WSL2,可能存在端口转发冲突:

  • 关闭所有WSL实例:wsl --shutdown
  • 重启Docker Desktop(若正在使用),再尝试启动应用

3. 重置Windows网络栈

执行以下命令重置网络设置:

netsh int ip reset
netsh winsock reset

执行完成后重启电脑,再启动应用。

4. 检查安全软件拦截

临时关闭第三方杀毒软件、防火墙,或在Windows防火墙中给React应用添加允许通过的规则,排查是否是安全软件拦截了端口绑定。

5. 指定应用绑定地址

修改package.json中的启动脚本,指定绑定到0.0.0.0而非localhost:

"scripts": {
  "start": "HOST=0.0.0.0 react-scripts start"
}

或在Windows终端临时设置环境变量后启动:
set HOST=0.0.0.0 && npm start

6. 修复hosts文件配置

当前hosts中注释了localhost的映射,可能导致DNS解析异常。取消以下两行的注释:

127.0.0.1       localhost
::1             localhost

保存后刷新DNS:ipconfig /flushdns,再启动应用。

内容的提问来源于stack exchange,提问作者Clunis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 16:27:37