【发布时间】:2019-02-15 16:35:00
【问题描述】:
我有一个应用程序,后端有节点,前端有反应。我有一个 npm 开发脚本在我的服务器 package.json 上同时运行,如下所示:
"server": "nodemon server.js",
"client": "npm start --prefix client",
"watch:sass": "npm run watch:sass --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\" \"npm run watch:sass\""
这在我准备部署之前一直运行良好,我在我的客户端文件夹 package.json 下运行了我的 react-scripts build。
我的服务器侦听端口 3000,我使用如下代理设置我的 react-sripts:"proxy": "http://localhost:8000"。
每当我尝试运行 npm run dev 时,我的 react 构建后都会出现以下错误:Something is already running on port 3000。
是的,我已尝试使用sudo lsof -i:3000 列出并查看在该端口上运行的所有进程,是的,我已尝试使用killall node 进程。
我已尝试更改 app.listen() 上的端口或将 react-scripts start 更改为 PORT=3001 react-scripts start 和 YES 这将解决我最初的问题,但是问题是我似乎无法让我的正面与背面进行通信,并且我的所有 API 调用都不起作用。
Proxy error: Could not proxy request /api/users/login from localhost:3000 to http://localhost:8000.
See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
有什么想法吗?谢谢。
【问题讨论】: