【问题标题】:Application error after succeeded Heroku Build (Node + React App)Heroku Build 成功后的应用程序错误(Node + React App)
【发布时间】:2018-09-15 09:39:59
【问题描述】:

我创建了一个带有 Nodejs 后端的 React 应用程序(使用 CRA)。现在我尝试托管它。 (我托管了几个具有相同堆栈的应用程序,但没有遇到任何问题)。

我正在使用 concurrently 模块和 npm run dev 启动 Nodejs 和 React 应用程序。 但是这次我遇到了一个错误,我不知道为什么。

这是我打开链接时得到的。

应用程序错误

应用程序发生错误,无法提供您的页面。如果您是应用程序所有者,请查看您的日志以了解详细信息。

index.js
const express = require('express');
const routes = require('./routes');
const app = express();

const port = 5000 || process.env.PORT;

routes(app);

if(process.env.NODE_ENV === 'production'){
    app.use(express.static('client/build'));
    const path = require('path');
    app.get("*", (req,res) =>  {
      res.sendFile(path.resolve(__dirname,'client','build','index.html'));
    })
  }

app.listen(port, () => console.log(`Server is running on port ${port}`));
包.json
{
  "name": "check-market",
  "version": "1.0.0",
  "description": "This is a react-nodejs based crypto market checking app",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "server": "nodemon index.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "client": "npm run start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "author": "abcd",
  "license": "ISC",
  "dependencies": {
    "concurrently": "^3.5.1",
    "cryptocoins-icons": "^2.7.0",
    "express": "^4.16.2",
    "node-fetch": "^2.0.0",
    "nodemon": "^1.14.12"
  }
}
heroku 日志
2018-04-05T13:41:49.283535+00:00 app[web.1]: [1]2018-04-05T13:41:49.560174+00:00 app[web.1]: [0] Server is running on port 5000
2018-04-05T13:41:51.049613+00:00 app[web.1]: [1] Starting the development server...
2018-04-05T13:41:51.049625+00:00 app[web.1]: [1]
2018-04-05T13:41:51.202463+00:00 heroku[web.1]: State changed from starting to up
2018-04-05T13:42:00.969286+00:00 app[web.1]: [1] Compiled with warnings.
2018-04-05T13:42:00.969303+00:00 app[web.1]: [1]
2018-04-05T13:42:00.969584+00:00 app[web.1]: [1] ./src/components/currency_main.js
2018-04-05T13:42:00.969587+00:00 app[web.1]: [1]   Line 49:  Expected to return a value in arrow function  array-callback-return
2018-04-05T13:42:00.969588+00:00 app[web.1]: [1]
2018-04-05T13:42:00.969590+00:00 app[web.1]: [1] Search for the keywords to learn more about each warning.
2018-04-05T13:42:00.969593+00:00 app[web.1]: [1] To ignore, add // eslint-disable-next-line to the line before.
2018-04-05T13:42:00.969594+00:00 app[web.1]: [1]2018-04-05T13:42:17.377067+00:00 heroku[router]: at=info method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=fa334992-ebb7-4a38-8c2d-e5c09849dcef fwd="112.134.75.196" dyno=web.1 connect=1ms service=13ms status=200 bytes=219 protocol=https
2018-04-05T13:42:18.397503+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=e716c9cb-e910-4f98-8346-4195c6d623ca fwd="112.134.75.196" dyno=web.1 connect=0ms service=7ms status=200 bytes=219 protocol=https
2018-04-05T13:44:47.000000+00:00 app[api]: Build started by user thidasaone@gmail.com
2018-04-05T13:44:47.000000+00:00 app[api]: Build succeeded
2018-04-05T13:46:08.491686+00:00 app[api]: Deploy 0ae9d4f3 by user thidasaone@gmail.com2018-04-05T13:46:08.491686+00:00 app[api]: Release v8 created by user thidasaone@gmail.com2018-04-05T13:46:10.417551+00:00 heroku[web.1]: Restarting
2018-04-05T13:46:10.418403+00:00 heroku[web.1]: State changed from up to starting2018-04-05T13:46:12.169322+00:00 heroku[web.1]: Stopping all processes with SIGTERM2018-04-05T13:46:12.258942+00:00 heroku[web.1]: Process exited with status 143
2018-04-05T13:46:17.859328+00:00 heroku[web.1]: Starting process with command `npm run dev`2018-04-05T13:46:20.219087+00:00 app[web.1]:2018-04-05T13:46:20.219128+00:00 app[web.1]: > check-market@1.0.0 dev /app
2018-04-05T13:46:20.219130+00:00 app[web.1]: > concurrently "npm run server" "npm run client"2018-04-05T13:46:20.219132+00:00 app[web.1]:2018-04-05T13:46:20.817238+00:00 app[web.1]: [0]
2018-04-05T13:46:20.817262+00:00 app[web.1]: [0] > check-market@1.0.0 server /app
2018-04-05T13:46:20.817265+00:00 app[web.1]: [0] > nodemon index.js
2018-04-05T13:46:20.817267+00:00 app[web.1]: [0]
2018-04-05T13:46:20.865621+00:00 app[web.1]: [1]
2018-04-05T13:46:20.865626+00:00 app[web.1]: [1] > check-market@1.0.0 client /app
2018-04-05T13:46:20.865635+00:00 app[web.1]: [1] > npm run start --prefix client
2018-04-05T13:46:20.865636+00:00 app[web.1]: [1]
2018-04-05T13:46:21.154092+00:00 app[web.1]: [0] [nodemon] 1.14.12
2018-04-05T13:46:21.155353+00:00 app[web.1]: [0] [nodemon] to restart at any time, enter `rs`
2018-04-05T13:46:21.155695+00:00 app[web.1]: [0] [nodemon] watching: *.*
2018-04-05T13:46:21.156422+00:00 app[web.1]: [0] [nodemon] starting `node index.js`
2018-04-05T13:46:21.225033+00:00 app[web.1]: [1]
2018-04-05T13:46:21.225037+00:00 app[web.1]: [1] > client@0.1.0 start /app/client
2018-04-05T13:46:21.225039+00:00 app[web.1]: [1] > react-scripts start
2018-04-05T13:46:21.225041+00:00 app[web.1]: [1]
2018-04-05T13:46:21.390693+00:00 app[web.1]: [0] Server is running on port 5000
2018-04-05T13:46:22.929315+00:00 app[web.1]: [1] [HPM] Proxy created: function (pathname) {
2018-04-05T13:46:22.929329+00:00 app[web.1]: [1]         return mayProxy(pathname) && pathname.match(context);
2018-04-05T13:46:22.929331+00:00 app[web.1]: [1]       }  ->  http://localhost:5000
2018-04-05T13:46:22.940428+00:00 app[web.1]: [1] Starting the development server...
2018-04-05T13:46:22.940431+00:00 app[web.1]: [1]
2018-04-05T13:46:23.520069+00:00 heroku[web.1]: State changed from starting to up
2018-04-05T13:46:31.231306+00:00 heroku[router]: at=info method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=ec7762d5-3d9d-4512-96bf-5e51fd57e531 fwd="112.134.75.196" dyno=web.1 connect=1ms service=35ms status=304 bytes=150 protocol=https
2018-04-05T13:46:32.041938+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=51901fca-b454-4e15-891f-54157d6ecffa fwd="112.134.75.196" dyno=web.1 connect=1ms service=74ms status=304 bytes=150 protocol=https
2018-04-05T13:46:34.656623+00:00 app[web.1]: [1]
2018-04-05T13:46:34.656609+00:00 app[web.1]: [1] Compiled with warnings.
2018-04-05T13:46:34.656627+00:00 app[web.1]: [1]   Line 49:  Expected to return a value in arrow function  array-callback-return
2018-04-05T13:46:34.656629+00:00 app[web.1]: [1]
2018-04-05T13:46:34.656650+00:00 app[web.1]: [1] Search for the keywords to learn more about each warning.
2018-04-05T13:46:34.656625+00:00 app[web.1]: [1] ./src/components/currency_main.js
2018-04-05T13:46:34.656652+00:00 app[web.1]: [1] To ignore, add // eslint-disable-next-line to the line before.
2018-04-05T13:46:34.656654+00:00 app[web.1]: [1]
2018-04-05T13:47:01.000000+00:00 app[api]: Build started by user thidasaone@gmail.com
2018-04-05T13:48:18.696342+00:00 heroku[router]: at=info method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=9b941ec9-ac57-465f-8270-ff6b576e7a7e fwd="112.134.75.196" dyno=web.1 connect=1ms service=4ms status=304 bytes=150 protocol=https
2018-04-05T13:48:19.715353+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=9dce4cdb-3251-4371-a6dc-17f5157c4c91 fwd="112.134.75.196" dyno=web.1 connect=1ms service=4ms status=200 bytes=219 protocol=https
2018-04-05T13:48:23.281435+00:00 heroku[web.1]: Restarting
2018-04-05T13:48:23.283219+00:00 heroku[web.1]: State changed from up to starting
2018-04-05T13:48:24.367174+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-04-05T13:48:24.460758+00:00 heroku[web.1]: Process exited with status 143
2018-04-05T13:48:22.235400+00:00 app[api]: Deploy f9c11456 by user thidasaone@gmail.com
2018-04-05T13:48:22.235400+00:00 app[api]: Release v9 created by user thidasaone@gmail.com
2018-04-05T13:47:01.000000+00:00 app[api]: Build succeeded
2018-04-05T13:48:31.022921+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-05T13:48:32.988916+00:00 app[web.1]:
2018-04-05T13:48:32.988939+00:00 app[web.1]: > check-market@1.0.0 start /app
2018-04-05T13:48:32.988941+00:00 app[web.1]: > node index.js
2018-04-05T13:48:32.988943+00:00 app[web.1]:
2018-04-05T13:48:33.185499+00:00 app[web.1]: Server is running on port 5000
2018-04-05T13:49:31.116916+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2018-04-05T13:49:31.093326+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 secondsof launch
2018-04-05T13:49:31.093493+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-04-05T13:49:31.174105+00:00 heroku[web.1]: Process exited with status 22
2018-04-05T13:49:31.188588+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-05T13:49:31.190801+00:00 heroku[web.1]: State changed from crashed to starting
2018-04-05T13:49:41.680073+00:00 heroku[web.1]: Starting process with command `npm start`
2018-04-05T13:49:44.021163+00:00 app[web.1]:
2018-04-05T13:49:44.021180+00:00 app[web.1]: > check-market@1.0.0 start /app
2018-04-05T13:49:44.021181+00:00 app[web.1]: > node index.js
2018-04-05T13:49:44.021183+00:00 app[web.1]:
2018-04-05T13:49:44.261412+00:00 app[web.1]: Server is running on port 5000
2018-04-05T13:50:24.659139+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=19ee5172-d09e-4a14-bec5-7332c5b8b572 fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:50:42.173853+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 secondsof launch
2018-04-05T13:50:42.173971+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-04-05T13:50:42.278113+00:00 heroku[web.1]: Process exited with status 137
2018-04-05T13:50:42.292645+00:00 heroku[web.1]: State changed from starting to crashed
2018-04-05T13:50:44.109644+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=457aceaf-7149-4cd8-aaf0-1e9746c2e7a9 fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:50:46.073884+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=6d2ed2ed-a2dc-4b77-80f1-099d442e16db fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:50:55.112767+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=51e6ee29-3f28-4dc1-bc69-b58604b6524b fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:51:02.307944+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=5e366ae1-6d66-4015-85ad-e407316d083f fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:51:24.537650+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cryptic-hollows-53642.herokuapp.com request_id=8483caf1-1e99-4735-a16e-8df0d09b3d20 fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https
2018-04-05T13:51:27.770178+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cryptic-hollows-53642.herokuapp.com request_id=28e8927c-21ac-44c5-84e5-093f55c95aeb fwd="112.134.75.196" dyno= connect= service= status=503 bytes= protocol=https

正如我在 heroku 日志中看到的,我知道存在问题(正如它所提到的)。但我无法弄清楚它是什么,因为我遵循了与以前相同的步骤(与我在 Heroku 上托管其他应用程序一样)

谁能告诉我我做错了什么?

附注: 我检查了this 并添加了 Procfile ,然后我遇到了 React App 的问题,说 Invalid Header File 。所以我删除了它(因为 Heroku 在发布后的某个时间自动完成了这个过程)

我也咨询了this,但我认为这不会有任何帮助。

【问题讨论】:

    标签: node.js reactjs heroku


    【解决方案1】:

    我有同样的问题,我已经添加了上面提到的PORT 5000,但它本身并没有解决我的问题。

    无论如何通过检查构建日志,我发现了以下错误:

    错误:未定义配置属性“mongoURI”

    production.json 文件位于 .gitignore 文件中,通过将其从 .gitignore 中删除并将其推送到 Heroku,问题得到解决。

    【讨论】:

      【解决方案2】:

      尝试通过浏览将配置变量添加到您的 Heroku 应用程序中 您的应用 => 设置 => 显示配置变量 => 在其中添加 PORT 5000

      【讨论】:

        猜你喜欢
        • 2021-05-15
        • 1970-01-01
        • 1970-01-01
        • 2021-05-02
        • 1970-01-01
        • 2020-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多