微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Heroku - 有些东西已经在端口 5000 上运行了?

如何解决Heroku - 有些东西已经在端口 5000 上运行了?

首先,我在stackoverflow上检查了整个问题,但找不到解决方案。当我尝试通过 npm run dev 运行我的应用程序时,一切正常。当我尝试在 VS Code 中保存某些内容时(应用程序崩溃,因为某些内容在端口 5000 上运行)然后我必须一遍又一遍地更改终端、npx kill-port 5000 和 npm run dev。

require("dotenv").config();
const express = require("express");
const app = express();
const productRoutes = require("./routes/productRoutes");
const connectDB = require("./config/db");




const path = require("path");


if(process.env.NODE_ENV === 'production') { 
app.use(express.static('../client/build'));

app.get('*',(req,res) => {
res.sendFile(path.resolve(__dirname,'client','build','index.html'));
});
} 
 
 
  
connectDB();
 
app.use(express.json());
 
app.get("/",res) => { 
  res.json({ message: "API running..." });
});

app.use("/api/products",productRoutes);

const PORT = process.env.PORT || 5000;
app.listen(PORT,() => console.log(`Server running on port ${PORT}`));
 

Package.json

  "scripts": {
    "server": "nodemon backend/server.js","client": "npm start --prefix client","dev": "concurrently \"npm run server\" \"npm run client\"","data:import": "node backend/seederScript","build": "cd client && npm run build","install-client": "cd client && npm install","heroku-postbuild": "NPM_CONfig_PRODUCTION=false npm install --prefix client && npm run build --prefix client","develop": "concurrently --kill-others-on-fail \"npm run server\" \"npm run start --prefix client\"","start": "concurrently --kill-others-on-fail \"npm run server\" \"npm run start --prefix client\""
  },

当我尝试在本地运行 heroku 时,即使我杀死了该端口,该端口上也已经运行了一些东西

https://github.com/TomaszSygut/Shopping-cart

如果有人知道发生了什么,请帮助我。我已经在那个奇怪的错误上花了 2 天时间

解决方法

2021-06-23T12:12:46.000000+00:00 app[api]: Build started by user thomassygut@gmail.com
2021-06-23T12:14:54.513779+00:00 app[api]: Release v5 created by user thomassygut@gmail.com
2021-06-23T12:14:54.513779+00:00 app[api]: Deploy 9ceb0c19 by user thomassygut@gmail.com
2021-06-23T12:14:55.204758+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-23T12:14:57.000000+00:00 app[api]: Build succeeded
2021-06-23T12:15:06.592623+00:00 heroku[web.1]: Starting process with command `npm start`
2021-06-23T12:15:09.222001+00:00 app[web.1]: 
2021-06-23T12:15:09.222019+00:00 app[web.1]: > mern-shoppingcart-redux@1.0.0 start /app
2021-06-23T12:15:09.222020+00:00 app[web.1]: > concurrently --kill-others-on-fail "npm run server" "npm run start --prefix client"
2021-06-23T12:15:09.222020+00:00 app[web.1]: 
2021-06-23T12:15:09.249330+00:00 app[web.1]: sh: 1: concurrently: not found
2021-06-23T12:15:09.252247+00:00 app[web.1]: npm ERR! file sh
2021-06-23T12:15:09.252540+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-06-23T12:15:09.252732+00:00 app[web.1]: npm ERR! errno ENOENT
2021-06-23T12:15:09.252908+00:00 app[web.1]: npm ERR! syscall spawn
2021-06-23T12:15:09.253986+00:00 app[web.1]: npm ERR! mern-shoppingcart-redux@1.0.0 start: `concurrently --kill-others-on-fail "npm run server" "npm run start --prefix client"`
2021-06-23T12:15:09.254100+00:00 app[web.1]: npm ERR! spawn ENOENT
2021-06-23T12:15:09.254327+00:00 app[web.1]: npm ERR!
2021-06-23T12:15:09.254441+00:00 app[web.1]: npm ERR! Failed at the mern-shoppingcart-redux@1.0.0 start script.
2021-06-23T12:15:09.254573+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-06-23T12:15:09.263627+00:00 app[web.1]: 
2021-06-23T12:15:09.263773+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-06-23T12:15:09.263872+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-06-23T12_15_09_255Z-debug.log
2021-06-23T12:15:09.344222+00:00 heroku[web.1]: Process exited with status 1
2021-06-23T12:15:09.410230+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-23T12:15:09.414393+00:00 heroku[web.1]: State changed from crashed to starting
2021-06-23T12:15:23.748088+00:00 heroku[web.1]: Starting process with command `npm start`
2021-06-23T12:15:26.383257+00:00 app[web.1]: 
2021-06-23T12:15:26.383287+00:00 app[web.1]: > mern-shoppingcart-redux@1.0.0 start /app
2021-06-23T12:15:26.383288+00:00 app[web.1]: > concurrently --kill-others-on-fail "npm run server" "npm run start --prefix client"
2021-06-23T12:15:26.383289+00:00 app[web.1]: 
2021-06-23T12:15:26.388074+00:00 app[web.1]: sh: 1: concurrently: not found
2021-06-23T12:15:26.394007+00:00 app[web.1]: npm ERR! file sh
2021-06-23T12:15:26.394493+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-06-23T12:15:26.394934+00:00 app[web.1]: npm ERR! errno ENOENT
2021-06-23T12:15:26.395258+00:00 app[web.1]: npm ERR! syscall spawn
2021-06-23T12:15:26.397033+00:00 app[web.1]: npm ERR! mern-shoppingcart-redux@1.0.0 start: `concurrently --kill-others-on-fail "npm run server" "npm run start --prefix client"`
2021-06-23T12:15:26.397313+00:00 app[web.1]: npm ERR! spawn ENOENT
2021-06-23T12:15:26.397658+00:00 app[web.1]: npm ERR!
2021-06-23T12:15:26.397902+00:00 app[web.1]: npm ERR! Failed at the mern-shoppingcart-redux@1.0.0 start script.
2021-06-23T12:15:26.398179+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-06-23T12:15:26.407147+00:00 app[web.1]: 
2021-06-23T12:15:26.407449+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-06-23T12:15:26.407673+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-06-23T12_15_26_400Z-debug.log
2021-06-23T12:15:26.468310+00:00 heroku[web.1]: Process exited with status 1
2021-06-23T12:15:26.643298+00:00 heroku[web.1]: State changed from starting to crashed
2021-06-23T12:16:01.052036+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mini-shopping-app-demo.herokuapp.com request_id=c0f9a708-ddb7-4923-b5cc-b1b15fb61bca fwd="83.14.122.73" dyno= connect= service= status=503 bytes= protocol=https
2021-06-23T12:16:01.542494+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mini-shopping-app-demo.herokuapp.com request_id=f5e95ed2-5b89-4dbc-ac4c-0b3c582ae5d1 fwd="83.14.122.73" dyno= connect= service= status=503 bytes= protocol=https
2021-06-23T12:34:24.211883+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mini-shopping-app-demo.herokuapp.com request_id=36fe077b-9763-4056-86b7-228e9726f08a fwd="83.14.122.73" dyno= connect= service= status=503 bytes= protocol=https
2021-06-23T12:34:24.720272+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mini-shopping-app-demo.herokuapp.com request_id=ee3de3f0-fdd8-4978-9952-76b8f487c990 fwd="83.14.122.73" dyno= connect= service= status=503 bytes= protocol=https

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。