繁体   English   中英

heroku 本地 web 工作正常但部署不正常

[英]heroku local web works fine but deployment doesn't work properly

应用程序由 Node.js 和 React 组成。 没有数据库。 Heroku 本地 web 工作正常但部署不正常。 部署只有 index.html。 简而言之,node 和 react 在部署时无法正常工作。

后端 package.json

"engines": {
  "node": "15.4.0",
  "npm": "7.20.5"
},
"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "node app.js",
  "heroku-postbuild": "cd frontend && npm install && npm run build"
}

前端 package.json

"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test",
  "eject": "react-scripts eject"
},
"proxy": "http://localhost:5000"

应用程序.js

app.use(express.static(path.join(__dirname, './frontend/build')));
app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname+'/frontend/build/index.html'));
});
const PORT = process.env.PORT || 5000;

简介

web: node app.js

上面的heroku local web代码一切正常。 但是在部署时我遇到了这样的错误:

我得到的错误

Stopping all processes with SIGTERM
heroku[web.1]: Process exited with status 143

我在这里尝试了一些解决方案。 但是我无法解决。 我可以根据需要写更多信息。 谢谢!

将这些添加到您的前端 package.json 脚本中:

"devStart": "react-scripts start",
"start": "serve -s build",
....
"heroku-postbuild": "npm run build"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM