[英]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.