Heroku 产生错误 H10 并导致应用程序崩溃

Posted

技术标签:

【中文标题】Heroku 产生错误 H10 并导致应用程序崩溃【英文标题】:Heroku producing Error H10 and crashing app 【发布时间】:2020-08-09 08:12:23 【问题描述】:

我正在使用 nodejs + reactjs + express + mongodb

在另一台服务器上部署了我的后端,它的工作非常好。

但是当我访问前端时,它显示“H10”错误,当我使用 heroku local 它工作得非常好。

我的 package.json


  "name": "ecommerce",
  "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",
    "braintree-web-drop-in-react": "^1.1.1",
    "concurrently": "^5.2.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.1",
    "react-stripe-checkout": "^2.6.3"
  ,
  "scripts": 
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "heroku-postbuild": "npm run build"
  ,
  "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"
    ]
  ,
  "engines": 
    "node": "10.x",
    "npm": "6.x"
  

我得到的日志:

2020-04-25T18:04:45.413902+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=ecommerce-frontend-dweep.herokuapp.com request_id=0d7f7627-3a3e-4a79-8221-b09f89fb49d0 fwd="103.240.77.140" dyno= connect= service= status=503 bytes= protocol=https
2020-04-25T18:04:46.267420+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=ecommerce-frontend-dweep.herokuapp.com request_id=30e4c07f-fd30-4210-8158-dabbd7d196f9 fwd="103.240.77.140" dyno= connect= service= status=503 bytes= protocol=https

同时运行heroku run node console

输出(如果需要):

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module '/app/console'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

已经尝试过First Heroku deploy failed `error code=H10`的解决方案,但没有成功

【问题讨论】:

已解决:如果有人遇到同样的错误,请尝试以下步骤dev.to/webdevraj/… 【参考方案1】:

对我来说同样的问题,按照下面的步骤操作后效果很好:

首先尝试安装serve

npm install serve --s

然后将 package.json 中的脚本替换为:

"scripts": 
"dev": "react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"heroku-postbuild": "npm run build"

之后添加,提交并推送到heroku

【讨论】:

以上是关于Heroku 产生错误 H10 并导致应用程序崩溃的主要内容,如果未能解决你的问题,请参考以下文章

React 应用程序在本地运行,在 Heroku 错误代码 = H10 时崩溃

Spring Boot应用程序在Heroku代码= H10上崩溃

Heroku 应用程序崩溃

Heroku H10错误 - Python

Flask Heroku 部署的 Librosa 安装:“OSError: sndfile library not found”(H10 错误)

由于 Error=H10,Flask App 在通过 Heroku 部署时导致应用程序错误