如何解决部署在 heroku 上的 MERN 堆栈项目中的错误
我已经创建了一个完整的 MERN 项目并将其部署在 Heroku 上。但它不起作用。它会导致一些错误
2021-04-03T05:13:48.601333+00:00 app[web.1]: npm ERR!
2021-04-03T05:13:48.601635+00:00 app[web.1]: npm ERR! Failed at the server@1.0.0 start script.
2021-04-03T05:13:48.601904+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-04-03T05:13:48.628094+00:00 app[web.1]:
2021-04-03T05:13:48.628477+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-04-03T05:13:48.628718+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2021-04-03T05_13_48_603Z-debug.log
2021-04-03T05:13:48.724467+00:00 heroku[web.1]: Process exited with status 1
2021-04-03T05:13:48.813926+00:00 heroku[web.1]: State changed from starting to crashed
2021-04-03T07:33:34.448383+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=student-help-portal.herokuapp.com request_id=9a9f276d-57b4-4414-898e-e47229a853c1 fwd="106.213.162.11" dyno= connect= service= status=503 bytes= protocol=https
2021-04-03T07:33:35.088427+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=student-help-portal.herokuapp.com request_id=1ff051a0-0fad-4eb5-b993-489618f68a72 fwd="106.213.162.11" dyno= connect= service= status=503 bytes= protocol=https
部署的链接是:https://student-help-portal.herokuapp.com/
我不知道我是如何处理这个问题的。这个项目很容易在本地主机上运行。请帮我我该怎么办?
App.js 看起来像:
const { static,urlencoded } = require("express");
const express = require("express");
const path = require("path");
const cookieparser = require("cookie-parser");
const hbs = require("hbs");
const { kMaxLength } = require("buffer");
require('../Server/db/dbconnection');
const port = process.env.PORT || 5000;
const app = express();
const cors =require('cors')
var bodyParser = require('body-parser')
app.use(cors())
app.use(express.static(path.join(__dirname,'../Server/public/')))
const view_path = path.join(__dirname,'../Server/public');
const partials_path = path.join(__dirname,'../Server/templates');
app.use(express.json());
// app.use(bodyParser.json({limit:'10mb'}))
app.use(express.urlencoded({ extended: false }));
app.set("view engine","hbs");
app.set("views",view_path);
app.use(cookieparser());
hbs.registerPartials(partials_path);
app.use(require("../Server/Router/auth"));
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'));
})
}
app.listen(port,() => {
console.log(`Server Is Runing At Port No ${port}`);
});
我的node js服务器的package.json文件是:
{
"name": "server","version": "1.0.0","description": "","main": "app.js","scripts": {
"start": "node app.js","heroku-postbuild": "NPM_CONfig_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},"author": "Keval Dhol","license": "ISC","dependencies": {
"bcryptjs": "^2.4.3","cloudinary": "^1.25.1","cookie-parser": "^1.4.5","cors": "^2.8.5","express": "^4.17.1","hbs": "^4.1.1","jsonwebtoken": "^8.5.1","mongoose": "^5.11.11","multer": "^1.4.2","nodemailer": "^6.5.0","validator": "^13.5.2"
}
}
react 的package.json 文件为:
{
"name": "client","version": "0.1.0","private": true,"proxy": "http://localhost:5000/","dependencies": {
"@ckeditor/ckeditor5-build-classic": "^25.0.0","@ckeditor/ckeditor5-react": "^3.0.1","@material-ui/core": "^4.11.3","@material-ui/icons": "^4.11.2","@testing-library/jest-dom": "^5.11.9","@testing-library/react": "^11.2.5","@testing-library/user-event": "^12.7.3","axios": "^0.21.1","node-html-parser": "^3.0.3","react": "^17.0.1","react-dom": "^17.0.1","react-html-parser": "^2.0.2","react-router-dom": "^5.2.0","react-rte": "^0.16.3","react-scripts": "4.0.3","web-vitals": "^1.1.0"
},"scripts": {
"start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject"
},"eslintConfig": {
"extends": [
"react-app","react-app/jest"
]
},"browserslist": {
"production": [
">0.2%","not dead","not op_mini all"
],"development": [
"last 1 chrome version","last 1 firefox version","last 1 safari version"
]
}
}
这是我需要更改或添加的文件才能在 heroku 上成功运行此项目。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。