在 Heroku 上部署 nextjs 应用程序 - 错误状态 H20

soo*_*lai 2 heroku reactjs next.js

我是 React 和 nextjs 的新手。我设法在 nextjs 中开发了一个简单的网站,当我在本地系统中构建项目时,npm run build没有任何错误,它工作正常,然后我尝试在仪表板中的 heroku 中部署,它显示构建成功并部署,但是当我使用给定的检查项目时链接显示应用程序错误。在我检查 Heroku 日志后,它显示Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch如下。通过检查有关此链接的一些线程,我设法重新启动heroku,但没有使用仍然存在相同的问题。另外,我通过更改 package.json 将端口从 3000 更改为 5000。如果有人指出这个问题,这将非常有帮助。

  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start -p 5000"
  },
Run Code Online (Sandbox Code Playgroud)

这是我的 Heroku 日志

2020-07-24T05:14:15.020173+00:00 heroku[web.1]: Starting process with command `npm start`
2020-07-24T05:14:17.215400+00:00 app[web.1]:
2020-07-24T05:14:17.215416+00:00 app[web.1]: > abcapp@0.1.0 start /app
2020-07-24T05:14:17.215416+00:00 app[web.1]: > next start
2020-07-24T05:14:17.215416+00:00 app[web.1]:
2020-07-24T05:14:17.458010+00:00 app[web.1]: ready - started server on http://localhost:3000
2020-07-24T05:14:37.208072+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=abcapp.herokuapp.com request_id=55de2c51-58d2-430d-883d-7a1bc05cecfc fwd="157.46.187.156" dyno= connect= service= status=503 bytes= protocol=https
2020-07-24T05:15:15.482693+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-07-24T05:15:15.502706+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-07-24T05:15:15.584970+00:00 heroku[web.1]: Process exited with status 137
2020-07-24T05:15:15.629010+00:00 heroku[web.1]: State changed from starting to crashed
2020-07-24T05:15:17.145562+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=abcapp.herokuapp.com request_id=9e610deb-8e1e-4ca6-9e60-7516bc36cd92 fwd="157.46.187.156" dyno= connect= service= status=503 bytes= protocol=https
Run Code Online (Sandbox Code Playgroud)

soo*_*lai 5

我通过更新 package.json 解决了这个问题,如下所示。

  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start -p $PORT"
  },
Run Code Online (Sandbox Code Playgroud)