簡體   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