这是我在heroku部署中的第一次尝试,因此即使构建成功,我仍会遇到应用程序错误,这是我尝试在heroku上部署的现代应用程序,并且在本地服务器上也能正常运行。这是来自heroku网站的日志>
2020-10-16T11:00:59.763981+00:00 app[web.1]: npm ERR!
2020-10-16T11:00:59.763982+00:00 app[web.1]: npm ERR! Failed at the react-boiler-plate@1.0.0 start script.
2020-10-16T11:00:59.763983+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-10-16T11:00:59.794213+00:00 app[web.1]:
2020-10-16T11:00:59.794215+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-10-16T11:00:59.794215+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-10-16T11_00_59_764Z-debug.log
2020-10-16T11:00:59.897369+00:00 heroku[web.1]: Process exited with status 1
2020-10-16T11:00:59.964492+00:00 heroku[web.1]: State changed from starting to crashed
2020-10-16T11:11:55.766235+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=travelagencya.herokuapp.com request_id=b7e97425-227f-445c-8fb9-70b4f9a2e678 fwd="88.231.62.84" dyno= connect= service= status=503 bytes= protocol=https
2020-10-16T11:11:59.001442+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=travelagencya.herokuapp.com request_id=ba074c51-105a-4bff-b1fd-c428ee6d5dc6 fwd="88.231.62.84" dyno= connect= service= status=503 bytes= protocol=https
我整天都在搜索,没有mongodb的连接,我以为是什么问题。我可以提供进一步的信息,而且当我登录npm时,它更加精巧;
2020-10-16T10:34:01.745134+00:00 app[web.1]: internal/modules/cjs/loader.js:834
2020-10-16T10:34:01.745135+00:00 app[web.1]: throw err;
2020-10-16T10:34:01.745135+00:00 app[web.1]: ^
2020-10-16T10:34:01.745136+00:00 app[web.1]:
2020-10-16T10:34:01.745136+00:00 app[web.1]: Error: Cannot find module './prod'
2020-10-16T10:34:01.745136+00:00 app[web.1]: Require stack:
2020-10-16T10:34:01.745136+00:00 app[web.1]: - /app/server/config/key.js
2020-10-16T10:34:01.745137+00:00 app[web.1]: - /app/server/index.js
2020-10-16T10:34:01.745137+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)
package.json
{
"name": "react-boiler-plate",
"version": "1.0.0",
"description": "react boiler plate",
"main": "index.js",
"engine": {
"node": "10.16.0",
"npm": "6.9.0"
},
"scripts": {
"start": "node server/index.js",
"build": "cd client && npm run build",
"install-client": "cd client && npm install",
"heroku-postbuild": "npm run install-client && npm run build",
"backend": "nodemon server/index.js",
"frontend": "npm run start --prefix client",
"dev": "concurrently \"npm run backend\" \"npm run start --prefix client\""
},
"author": "Tolima",
"license": "ISC",
"dependencies": {
"bcrypt": "^3.0.6",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"cors": "^2.8.5",
"debug": "^4.1.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"moment": "^2.24.0",
"mongoose": "^5.4.20",
"multer": "^1.4.2",
"react-redux": "^5.0.7",
"saslprep": "^1.0.3",
"supports-color": "^7.1.0"
},
"devDependencies": {
"concurrently": "^4.1.0",
"nodemon": "^1.19.1"
}
}
index.js
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"));
});
}
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server Listening on ${port}`);
});