简体   繁体   English

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

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

App is consist of Node.js and React.应用程序由 Node.js 和 React 组成。 There is no database.没有数据库。 Heroku local web works fine but deployment doesn't work properly. Heroku 本地 web 工作正常但部署不正常。 Deployment just has index.html.部署只有 index.html。 In short words, node and react doesn't work properly on deployment.简而言之,node 和 react 在部署时无法正常工作。

backend package.json后端 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"
}

frontend package.json前端 package.json

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

app.js应用程序.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;

Procfile简介

web: node app.js

Everything is fine with the heroku local web code as above.上面的heroku local web代码一切正常。 But on deployment I met error like this:但是在部署时我遇到了这样的错误:

error I got我得到的错误

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

I tried some solutions in here.我在这里尝试了一些解决方案。 But I couldn't solve.但是我无法解决。 I can write more information as needed.我可以根据需要写更多信息。 Thanks!谢谢!

Add these to your frontend package.json scripts:将这些添加到您的前端 package.json 脚本中:

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

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

相关问题 套接字IO在本地计算机上运行良好,但在Heroku上不起作用 - Socket IO works fine on local machine but doesn't work on Heroku Express.js应用程序在本地可以正常运行,但是在Heroku上部署时无法正常工作 - Express.js app works fine locally but doesn't work when deployed on Heroku Sails JS-显示Flash消息不适用于Heroku(生产),但在开发中效果很好 - Sails JS - Display flash message doesn't work on Heroku(production) but works fine in development Javascript在Heroku中不起作用,但在本地环境中不起作用 - Javascript Doesn't Work in Heroku but in Local Environment Firefox无法正常播放动画gif(在Chrome中运行正常) - Firefox doesn't play animated gif properly (works fine in Chrome) Rails 4-在Heroku上部署后,Javascript不起作用 - Rails 4 - Javascript doesn't work after the deployment on Heroku javascript中的click()无法正常运行,但在控制台中可以正常运行 - click() in javascript doesn't work but in console it works fine Javascript在IE中不起作用,在其他所有方面都可以正常工作 - Javascript doesn't work in IE, works fine in everything else WebDriverIO 6 – $ 工作正常,$ 在 iframe 中不起作用 - WebDriverIO 6 – $ works fine, $ doesn't work in iframe 为什么这个 function 在 Safari 中不起作用? (在 Chrome 中工作正常) - Why doesn't this function work in Safari? (works fine in Chrome)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM