node.js - 将 node.js Web 应用程序部署到 Heroku 时出现 H10 应用程序崩溃错误
问题描述
我正在尝试在 Heroku 上部署我的 node.js Web 应用程序,但我不断收到“应用程序崩溃”错误。我已经尝试了我在互联网上找到的所有解决方案,但似乎没有一个有效。日志如下:
heroku logs --tail
2020-12-16T20:31:26.148157+00:00 app[api]: Release v23 created by user <myemail>@gmail.com
2020-12-16T20:31:26.148157+00:00 app[api]: Deploy f6c6d04d by user <myemail>@gmail.com
2020-12-16T20:31:26.468824+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-16T20:31:34.000000+00:00 app[api]: Build succeeded
2020-12-16T20:31:50.479221+00:00 heroku[web.1]: Starting process with command `npm start`
2020-12-16T20:31:54.351123+00:00 app[web.1]:
2020-12-16T20:31:54.351140+00:00 app[web.1]: > social-media-app@0.1.0 start /app
2020-12-16T20:31:54.351141+00:00 app[web.1]: > react-scripts start
2020-12-16T20:31:54.351141+00:00 app[web.1]:
2020-12-16T20:32:00.964824+00:00 app[web.1]: �� 「wds」: Project is running at http://172.19.71.206/
2020-12-16T20:32:00.965313+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-12-16T20:32:00.965424+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-12-16T20:32:00.965521+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-12-16T20:32:00.965744+00:00 app[web.1]: Starting the development server...
2020-12-16T20:32:00.965746+00:00 app[web.1]:
2020-12-16T20:32:01.091871+00:00 heroku[web.1]: Process exited with status 0
2020-12-16T20:32:01.137571+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-16T20:32:01.141435+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-16T20:32:21.012471+00:00 heroku[web.1]: Starting process with command `npm start`
2020-12-16T20:32:24.057205+00:00 app[web.1]:
2020-12-16T20:32:24.057227+00:00 app[web.1]: > social-media-app@0.1.0 start /app
2020-12-16T20:32:24.057227+00:00 app[web.1]: > react-scripts start
2020-12-16T20:32:24.057228+00:00 app[web.1]:
2020-12-16T20:32:26.955003+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.16.214.14/
2020-12-16T20:32:26.955707+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-12-16T20:32:26.955832+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-12-16T20:32:26.955945+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-12-16T20:32:26.956218+00:00 app[web.1]: Starting the development server...
2020-12-16T20:32:26.956220+00:00 app[web.1]:
2020-12-16T20:32:27.116530+00:00 heroku[web.1]: Process exited with status 0
2020-12-16T20:32:27.180961+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-16T20:32:28.442226+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=college-social-media-app.herokuapp.com request_id=1d2de790-c63b-4741-b5f3-65cc99538550 fwd="98.217.113.122" dyno= connect= service= status=503 bytes= protocol=https
2020-12-16T20:32:29.520392+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=college-social-media-app.herokuapp.com request_id=f17eb576-3131-4acd-8259-35c6ea119916 fwd="98.217.113.122" dyno= connect= service= status=503 bytes= protocol=https
2020-12-16T20:48:02.000000+00:00 app[api]: Build started by user <myemail>@gmail.com
2020-12-16T20:50:27.826733+00:00 app[api]: Release v24 created by user <myemail>@gmail.com
2020-12-16T20:50:27.826733+00:00 app[api]: Deploy ca7fd011 by user <myemail>@gmail.com
2020-12-16T20:50:28.015378+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-16T20:50:36.000000+00:00 app[api]: Build succeeded
2020-12-16T20:50:39.641800+00:00 heroku[web.1]: Starting process with command `npm start`
2020-12-16T20:50:44.110676+00:00 app[web.1]:
2020-12-16T20:50:44.110733+00:00 app[web.1]: > social-media-app@0.1.0 start /app
2020-12-16T20:50:44.110738+00:00 app[web.1]: > react-scripts start
2020-12-16T20:50:44.110738+00:00 app[web.1]:
2020-12-16T20:50:48.545375+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.216.142/
2020-12-16T20:50:48.546121+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-12-16T20:50:48.546385+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-12-16T20:50:48.546558+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-12-16T20:50:48.546939+00:00 app[web.1]: Starting the development server...
2020-12-16T20:50:48.546941+00:00 app[web.1]:
2020-12-16T20:50:48.657160+00:00 heroku[web.1]: Process exited with status 0
2020-12-16T20:50:48.705942+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-16T20:50:48.709177+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-16T20:51:14.285964+00:00 heroku[web.1]: Starting process with command `npm start`
2020-12-16T20:51:16.892012+00:00 app[web.1]:
2020-12-16T20:51:16.892044+00:00 app[web.1]: > social-media-app@0.1.0 start /app
2020-12-16T20:51:16.892045+00:00 app[web.1]: > react-scripts start
2020-12-16T20:51:16.892045+00:00 app[web.1]:
2020-12-16T20:51:20.008878+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.19.83.162/
2020-12-16T20:51:20.009454+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-12-16T20:51:20.009592+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-12-16T20:51:20.009709+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-12-16T20:51:20.009979+00:00 app[web.1]: Starting the development server...
2020-12-16T20:51:20.009981+00:00 app[web.1]:
2020-12-16T20:51:20.107792+00:00 heroku[web.1]: Process exited with status 0
2020-12-16T20:51:20.149048+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-16T20:51:21.146354+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=college-social-media-app.herokuapp.com request_id=e534c771-8266-47ff-9654-dbff9e06bcf3 fwd="98.217.113.122" dyno= connect= service= status=503 bytes= protocol=https
2020-12-16T20:51:21.890235+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=college-social-media-app.herokuapp.com request_id=12faed63-e137-4094-a8b1-abb0da32d249 fwd="98.217.113.122" dyno= connect= service= status=503 bytes= protocol=https
2020-12-16T21:03:26.100464+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=college-social-media-app.herokuapp.com request_id=b1f424f0-3bfa-450a-b966-f311444e79ec fwd="54.226.141.215" dyno= connect= service= status=503 bytes= protocol=http
2020-12-16T21:18:33.942775+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-16T21:18:43.329432+00:00 heroku[web.1]: Starting process with command `npm start`
2020-12-16T21:18:45.988296+00:00 app[web.1]:
2020-12-16T21:18:45.988318+00:00 app[web.1]: > social-media-app@0.1.0 start /app
2020-12-16T21:18:45.988318+00:00 app[web.1]: > react-scripts start
2020-12-16T21:18:45.988319+00:00 app[web.1]:
2020-12-16T21:18:48.317690+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.207.246/
2020-12-16T21:18:48.318135+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-12-16T21:18:48.318240+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-12-16T21:18:48.318338+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-12-16T21:18:48.318551+00:00 app[web.1]: Starting the development server...
2020-12-16T21:18:48.318553+00:00 app[web.1]:
2020-12-16T21:18:48.409919+00:00 heroku[web.1]: Process exited with status 0
2020-12-16T21:18:48.449952+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-16T21:41:45.930743+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=college-social-media-app.herokuapp.com request_id=71752592-39ff-4e7c-a322-40c51b30e9e5 fwd="94.130.167.123" dyno= connect= service= status=503 bytes= protocol=http
2020-12-16T21:41:46.160190+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=college-social-media-app.herokuapp.com request_id=2090702e-95cb-4f8c-ad07-0f84de7fbc46 fwd="94.130.167.123" dyno= connect= service= status=503 bytes= protocol=http
2020-12-16T22:26:03.650558+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-16T22:26:16.660922+00:00 heroku[web.1]: Starting process with command `npm start`
2020-12-16T22:26:18.817984+00:00 app[web.1]:
2020-12-16T22:26:18.818013+00:00 app[web.1]: > social-media-app@0.1.0 start /app
2020-12-16T22:26:18.818014+00:00 app[web.1]: > react-scripts start
2020-12-16T22:26:18.818014+00:00 app[web.1]:
2020-12-16T22:26:21.222563+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.28.182/
2020-12-16T22:26:21.223020+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-12-16T22:26:21.223111+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-12-16T22:26:21.223199+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-12-16T22:26:21.223417+00:00 app[web.1]: Starting the development server...
2020-12-16T22:26:21.223419+00:00 app[web.1]:
2020-12-16T22:26:21.313328+00:00 heroku[web.1]: Process exited with status 0
2020-12-16T22:26:21.348151+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-16T23:41:47.600206+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=college-social-media-app.herokuapp.com request_id=facfda12-0223-4bd1-848c-ba4b2ee99017 fwd="98.217.113.122" dyno= connect= service= status=503 bytes= protocol=https
2020-12-16T23:41:49.026899+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=college-social-media-app.herokuapp.com request_id=a0739ab1-be60-4a71-a4d8-51d12b860aa7 fwd="98.217.113.122" dyno= connect= service= status=503 bytes= protocol=https
这是我的 server.js 文件中的相关代码:
const app = express()
const port = process.env.PORT || 5000;
const uri = process.env.ATLAS_URI;
const userRouter = require('./routes/user')
app.use('/user', userRouter)
const homepageRouter = require('./routes/home')
app.use('/homepage', homepageRouter)
const forumRouter = require('./routes/forum')
app.use('/forum', forumRouter)
app.listen(port, () => {
console.log(`Server is running on port: ${port}`);
});
这是我的 ProcFile:
web:node src/index.js
web:node backend/server.js
这是我的 package.json 文件,它位于根目录中
{
"name": "social-media-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"bcrypt": "^5.0.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"express-pino-logger": "^5.0.0",
"gh-pages": "^3.1.0",
"mongodb": "^3.5.9",
"node-env-run": "^3.0.2",
"npm-run-all": "^4.1.5",
"pino-colada": "^2.0.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5000",
"secure": "false"
}
这是后端文件夹中的 package.json 文件:
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"server": "node-env-run server --exec nodemon | pino-colada",
"dev": "run-p server start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"mongoose": "^5.9.20"
},
"proxy": "http://localhost:5000"
}
我已经在 Heroku 控制台中设置了所需的配置变量,但 PORT 变量除外,因为 Heroku 应该在运行时创建自己的 PORT 变量。也许我的 package.json 文件中需要一些东西?我将不胜感激任何帮助。
解决方案
推荐阅读
- c++ - 在 linux 中使用 g++ 编译关于 std::basic_ios 的错误
- python - "errorMessage": "无法导入模块 'UpdateHost_Python'"
- php - php递归函数将嵌套{}分隔的字符串转换为数组
- c++ - 进程外 COM 对象动态版本控制
- javascript - 使用表外的总记录更新 Div
- python - 将值重新分配给函数的 args
- c# - 检查是否有任何功能成功,但执行所有
- python-3.x - 如何限制仅针对团队经理的批准操作
- mysql - 如何将具有不同值但名称相同的主键分组并使用 datediff
- airflow - 使用自定义状态标记气流任务