Antd Pro 服务挂掉 Disconnected from the devServer, trying to reconnect

更新日期: 2021-05-28 阅读次数: 5787 字数: 187 分类: ReactJS

今天发现 Antd Pro 的开发服务经常挂掉,浏览器中显示:

Disconnected from the devServer, trying to reconnect...

看起来是由于没有处理后台 404 的错误,导致前端 node 服务挂掉。。。

[HPM] Error occurred while trying to proxy request /api/upload-image from localhost:8000 to http://localhost:8088 (ECONNRESET) (https://nodejs.org/api/errors.html#errors_common_system_errors)
events.js:292
      throw er; // Unhandled 'error' event

然而我并没有找到可以包住异常的地方。

原来并不是 404 导致的问题,而是 proxy 的配置问题。

将 config/proxy.ts 中的 target 地址中的 localhost 替换成 127.0.0.1 即可。

再次启动服务,测试,就没有这个问题了。

不知道是不是因为这两天折腾 WSL 1 版本切换 2 导致的。

又挂了

[HPM] Error occurred while trying to proxy request /api/upload-image from localhost:8000 to http://127.0.0.1:8088

仔细看,本地 8000 也是 localhost。

cat /etc/hosts
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       DESKTOP-FST75GU.localdomain     DESKTOP-FST75GU

windows 里的也改了,还是不行。

浏览器里这样访问:

http://127.0.0.1:8000/

参考

https://github.com/saikat/react-apollo-starter-kit/issues/20

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式