【问题标题】:Heroku application crashed: at=error code=H10 desc=“App crashed” method=GET path=“/”Heroku 应用程序崩溃:at=error code=H10 desc=“App crashed” method=GET path=“/”
【发布时间】:2020-05-26 06:24:36
【问题描述】:

*我一直在尝试将我的 MERN 应用程序上传到 Heroku,并且收到了这些错误代码。 Web 应用程序将在我的本地主机上运行,​​但是当我尝试将其上传到 heroku 时,应用程序立即失败。我对使用 MERN 堆栈比较陌生,并且正在尝试弄清楚如何正确地将应用程序上传到 Heroku。 *

2020-05-26T05:00:40.804369+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=9c5806e4-dd49-4325-8814-dccb9f4398e0 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:00:41.404224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-fjord-39421.herokuapp.com request_id=c325a3c6-b459-4de2-b7f5-fe67457f8d6e fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=httpsenter code here
2020-05-26T05:01:09.373344+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=4ad4f358-063e-48d7-a55e-7ccffc32ffb3 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=httpsenter code here

heroku 日志 --tail

2020-05-26T04:54:22.910425+00:00 app[api]: Initial release by user woodjack191@gmail.com
2020-05-26T04:54:22.910425+00:00 app[api]: Release v1 created by user woodjack191@gmail.com
2020-05-26T04:54:23.096112+00:00 app[api]: Enable Logplex by user woodjack191@gmail.com
2020-05-26T04:54:23.096112+00:00 app[api]: Release v2 created by user woodjack191@gmail.com
2020-05-26T04:58:40.000000+00:00 app[api]: Build started by user woodjack191@gmail.com
2020-05-26T04:59:47.263635+00:00 app[api]: Deploy 7d333fc9 by user woodjack191@gmail.com
2020-05-26T04:59:47.263635+00:00 app[api]: Release v3 created by user woodjack191@gmail.com
2020-05-26T04:59:47.283454+00:00 app[api]: Scaled to web@1:Free by user woodjack191@gmail.com
2020-05-26T04:59:54.000000+00:00 app[api]: Build succeeded
2020-05-26T04:59:56.664155+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T04:59:59.487422+00:00 app[web.1]:
2020-05-26T04:59:59.487434+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T04:59:59.487434+00:00 app[web.1]: > react-scripts start
2020-05-26T04:59:59.487435+00:00 app[web.1]:
2020-05-26T05:00:02.028314+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.10.22/
2020-05-26T05:00:02.028881+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:00:02.029021+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:00:02.029167+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:00:02.029361+00:00 app[web.1]: Starting the development server...
2020-05-26T05:00:02.029362+00:00 app[web.1]: 
2020-05-26T05:00:02.141290+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:00:02.315545+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:00:02.318095+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:00:09.983236+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:00:12.651901+00:00 app[web.1]: 
2020-05-26T05:00:12.651922+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T05:00:12.651923+00:00 app[web.1]: > react-scripts start
2020-05-26T05:00:12.651923+00:00 app[web.1]:
2020-05-26T05:00:16.868981+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.17.178.250/
2020-05-26T05:00:16.869628+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:00:16.869783+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:00:16.869929+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:00:16.870239+00:00 app[web.1]: Starting the development server...
2020-05-26T05:00:16.870241+00:00 app[web.1]: 
2020-05-26T05:00:17.013391+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:00:17.057205+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:00:40.804369+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=9c5806e4-dd49-4325-8814-dccb9f4398e0 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:00:41.404224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-fjord-39421.herokuapp.com request_id=c325a3c6-b459-4de2-b7f5-fe67457f8d6e fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:01:09.373344+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-fjord-39421.herokuapp.com request_id=4ad4f358-063e-48d7-a55e-7ccffc32ffb3 fwd="71.204.55.234" dyno= connect= service= status=503 bytes= protocol=https
2020-05-26T05:11:05.245937+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:11:14.187854+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:11:16.938860+00:00 app[web.1]:
2020-05-26T05:11:16.938887+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T05:11:16.938887+00:00 app[web.1]: > react-scripts start
2020-05-26T05:11:16.938887+00:00 app[web.1]: 
2020-05-26T05:11:18.963210+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.19.50.2/
2020-05-26T05:11:18.963807+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:11:18.963915+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:11:18.964030+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:11:18.964316+00:00 app[web.1]: Starting the development server...
2020-05-26T05:11:18.964319+00:00 app[web.1]: 
2020-05-26T05:11:19.093706+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:11:19.137119+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-26T05:11:19.140236+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-26T05:11:26.041885+00:00 heroku[web.1]: Starting process with command `npm start`
2020-05-26T05:11:28.043546+00:00 app[web.1]: 
2020-05-26T05:11:28.043558+00:00 app[web.1]: > my-project@0.1.0 start /app
2020-05-26T05:11:28.043558+00:00 app[web.1]: > react-scripts start
2020-05-26T05:11:28.043559+00:00 app[web.1]:
2020-05-26T05:11:29.727646+00:00 app[web.1]: ℹ 「wds」: Project is running at http://172.16.13.198/
2020-05-26T05:11:29.727983+00:00 app[web.1]: ℹ 「wds」: webpack output is served from
2020-05-26T05:11:29.728062+00:00 app[web.1]: ℹ 「wds」: Content not from webpack is served from /app/public
2020-05-26T05:11:29.728128+00:00 app[web.1]: ℹ 「wds」: 404s will fallback to /
2020-05-26T05:11:29.728294+00:00 app[web.1]: Starting the development server...
2020-05-26T05:11:29.728295+00:00 app[web.1]:
2020-05-26T05:11:29.800107+00:00 heroku[web.1]: Process exited with status 0
2020-05-26T05:11:29.835462+00:00 heroku[web.1]: State changed from starting to crashed

server.js 文件

const bodyParser = require('body-parser');
const cors = require('cors');
const path = require('path')
const app = express();
require('./database');

app.use(bodyParser.json());
app.use(cors());

// API
const users = require('./api/users');
app.use('/api/users', users);

app.use(express.static(path.join(__dirname, '../build')))
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, '../build'))
})

const port = process.env.PORT || 5000;
app.listen(port, () => {
    console.log(`Server started on port ${port}`);
});

package.json 文件

{
  "name": "my-project",
  "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",
    "body-parser": "^1.19.0",
    "bootstrap": "^4.5.0",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "mongoose": "^5.9.15",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "node backend/server.js",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install npm && run build",
    "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",
  "engines": {
    "node": "10.16.0"
  }
}

【问题讨论】:

  • 1.尝试重新启动测功机... 2. 重置数据库 .... 我不是专家,但请尝试查看您的生产设置并将它们与 Heroku 上的指南相匹配。希望有帮助

标签: node.js reactjs express heroku mern


【解决方案1】:

这可以通过两种方式解决:

1) 如果忘记设置启动脚本,一般会抛出这个错误! Heroku 要求将 Procfile(如果您想覆盖 Heroku 的默认启动命令)与您的应用文件一起上传。

Procfile的内容应该是这样的:

web: node index.js(即指定要为您的应用程序运行的节点命令)

2) 如果您不想上传 Procfile,那么您可以在 package.json 中的 "scripts" 中指定您的命令(您已经完成了),同时您需要在 package.json 中添加 "build":"webpack" .

您还使用"heroku-postbuild" 替换了"build" 脚本......所以实际上它必须工作!但是您可以尝试上述两种方法中的一种并尝试对其进行调试(希望肯定可以使用)!

【讨论】:

    【解决方案2】:

    将此添加到您的 server.js:

    var distDir = __dirname + "/dist/";
    
    app.use(express.static(distDir));
    

    【讨论】:

      【解决方案3】:

      在 React 中我做了两件事。一个解决了:)

      1. 使用https://favicon.io/favicon-converter/ 添加了网站图标和清单
      2. package.json 中删除了未使用的包,您还应该将开发依赖项添加到devDependencies

      【讨论】:

        猜你喜欢
        • 2019-07-02
        • 1970-01-01
        • 1970-01-01
        • 2015-03-01
        • 2013-03-30
        • 2020-12-13
        • 1970-01-01
        • 2020-10-21
        • 2018-04-09
        相关资源
        最近更新 更多