【问题标题】:Node.js app not opening after deploy to Heroku部署到 Heroku 后 Node.js 应用程序未打开
【发布时间】:2018-01-02 08:58:00
【问题描述】:

我对我的代码进行了多次修改,并阅读了关于类似问题的各种相互冲突的博客文章。 应用在本地正确打开。

我采取的其他步骤:

  • 已清除并重新添加 nodejs buildpackm 根据 Heroku 文档缩放应用程序 (heroku ps:scale web=0) (heroku ps:scale web=1),重新启动 heroku 应用程序。最后,我对类似问题使用了以下答案:

Error while deploying Node.js App to Heroku

Heroku is giving me a 503 when trying to open my web app, works on local host

npm ERR! npm owner error triggered with H10 app crashed

在我看来,日志中的重大错误是:“heroku[router]: at=error code=H10 desc="App crashed"。

任何指导将不胜感激。

Heroku 日志:

macs-iMac:hooptime mac$ heroku logs
2017-07-27T03:13:32.290426+00:00 app[web.1]: Available on:
2017-07-27T03:13:32.291372+00:00 app[web.1]:   http://localhost:8000
2017-07-27T03:13:32.291437+00:00 app[web.1]: Hit CTRL-C to stop the server
2017-07-27T03:14:24.468772+00:00 heroku[web.1]: State changed from starting to crashed
2017-07-27T03:14:24.329875+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-07-27T03:14:24.329968+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-07-27T03:14:24.452131+00:00 heroku[web.1]: Process exited with status 137
2017-07-27T03:17:53.555938+00:00 heroku[worker.1]: State changed from crashed to starting
2017-07-27T03:17:58.615372+00:00 heroku[worker.1]: Starting process with command `node index.js`
2017-07-27T03:17:59.234914+00:00 heroku[worker.1]: State changed from starting to up
2017-07-27T03:18:01.127773+00:00 heroku[worker.1]: State changed from up to crashed
2017-07-27T03:18:01.028085+00:00 app[worker.1]: module.js:471
2017-07-27T03:18:01.028104+00:00 app[worker.1]:     throw err;
2017-07-27T03:18:01.028105+00:00 app[worker.1]:     ^
2017-07-27T03:18:01.028105+00:00 app[worker.1]: 
2017-07-27T03:18:01.028112+00:00 app[worker.1]: Error: Cannot find module '/app/index.js'
2017-07-27T03:18:01.028121+00:00 app[worker.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-07-27T03:18:01.028122+00:00 app[worker.1]:     at Function.Module._load (module.js:417:25)
2017-07-27T03:18:01.028123+00:00 app[worker.1]:     at Module.runMain (module.js:604:10)
2017-07-27T03:18:01.028123+00:00 app[worker.1]:     at run (bootstrap_node.js:389:7)
2017-07-27T03:18:01.028124+00:00 app[worker.1]:     at startup (bootstrap_node.js:149:9)
2017-07-27T03:18:01.028125+00:00 app[worker.1]:     at bootstrap_node.js:504:3
2017-07-27T03:18:01.111007+00:00 heroku[worker.1]: Process exited with status 1
2017-07-27T03:32:56.591479+00:00 heroku[worker.1]: State changed from crashed to starting
2017-07-27T03:33:00.576960+00:00 heroku[worker.1]: Starting process with command `node index.js`
2017-07-27T03:33:01.200876+00:00 heroku[worker.1]: State changed from starting to up
2017-07-27T03:33:02.638384+00:00 app[worker.1]: module.js:471
2017-07-27T03:33:02.638400+00:00 app[worker.1]:     throw err;
2017-07-27T03:33:02.638401+00:00 app[worker.1]:     ^
2017-07-27T03:33:02.638402+00:00 app[worker.1]: 
2017-07-27T03:33:02.638402+00:00 app[worker.1]: Error: Cannot find module '/app/index.js'
2017-07-27T03:33:02.638415+00:00 app[worker.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-07-27T03:33:02.638415+00:00 app[worker.1]:     at Function.Module._load (module.js:417:25)
2017-07-27T03:33:02.638416+00:00 app[worker.1]:     at Module.runMain (module.js:604:10)
2017-07-27T03:33:02.638417+00:00 app[worker.1]:     at run (bootstrap_node.js:389:7)
2017-07-27T03:33:02.638417+00:00 app[worker.1]:     at startup (bootstrap_node.js:149:9)
2017-07-27T03:33:02.638418+00:00 app[worker.1]:     at bootstrap_node.js:504:3
2017-07-27T03:33:02.769228+00:00 heroku[worker.1]: Process exited with status 1
2017-07-27T03:33:02.782955+00:00 heroku[worker.1]: State changed from up to crashed
2017-07-27T03:36:58.088482+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=04c12935-8d88-470d-9e54-4b45e2480d67 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:00.556550+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=270fea8f-75fe-4078-8c01-c8779e5c43cb fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:12.960183+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=d31437be-fe7e-4e56-a0db-a13a8e3a28af fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:13.804392+00:00 heroku[worker.1]: State changed from crashed to starting
2017-07-27T03:48:14.158976+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=d9cdb0e6-ab58-442f-b35b-87e72ae2cc18 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:14.505616+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/apple-touch-icon-precomposed.png" host=hooptime.herokuapp.com request_id=de46bfff-578e-4e5e-be86-c51b58b4af54 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:14.661681+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=e51259a7-0979-412d-8f93-b571e28875ef fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:14.743144+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/apple-touch-icon.png" host=hooptime.herokuapp.com request_id=fb7cd369-d821-44a1-bf30-5e378f1810fb fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:15.011171+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=82649af8-1b1c-4215-827b-41af4d827500 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:15.276467+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/apple-touch-icon-precomposed.png" host=hooptime.herokuapp.com request_id=fe831747-d46d-4ae2-9475-64bed439abb3 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:15.599565+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/apple-touch-icon.png" host=hooptime.herokuapp.com request_id=7e6fd0fa-efc7-40b6-b2da-125673765285 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:17.042432+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=4b51a77b-ae59-4583-b386-526f0a501c68 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:17.149974+00:00 heroku[worker.1]: Starting process with command `node index.js`
2017-07-27T03:48:17.380527+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=73136e3a-46b7-4c92-9f2a-d581d3c72738 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:48:17.829826+00:00 heroku[worker.1]: State changed from starting to up
2017-07-27T03:48:19.457599+00:00 app[worker.1]: module.js:471
2017-07-27T03:48:19.457612+00:00 app[worker.1]:     throw err;
2017-07-27T03:48:19.457612+00:00 app[worker.1]:     ^
2017-07-27T03:48:19.457613+00:00 app[worker.1]: 
2017-07-27T03:48:19.457614+00:00 app[worker.1]: Error: Cannot find module '/app/index.js'
2017-07-27T03:48:19.457615+00:00 app[worker.1]:     at Function.Module._load (module.js:417:25)
2017-07-27T03:48:19.457614+00:00 app[worker.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-07-27T03:48:19.457616+00:00 app[worker.1]:     at Module.runMain (module.js:604:10)
2017-07-27T03:48:19.457616+00:00 app[worker.1]:     at run (bootstrap_node.js:389:7)
2017-07-27T03:48:19.457618+00:00 app[worker.1]:     at bootstrap_node.js:504:3
2017-07-27T03:48:19.457617+00:00 app[worker.1]:     at startup (bootstrap_node.js:149:9)
2017-07-27T03:48:19.568292+00:00 heroku[worker.1]: Process exited with status 1
2017-07-27T03:48:19.582653+00:00 heroku[worker.1]: State changed from up to crashed
2017-07-27T03:53:32.129097+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=70af7304-5591-4cff-9fc7-25c309e6df5b fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:53:32.359600+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=13b24996-5231-46ce-bf16-0917f438d67c fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:54:22.676504+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=1b37ef83-7165-4f51-8028-e6e7c9223c30 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:54:22.902471+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=bab64ebe-b273-4b57-94e9-c795833e0f68 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:56:00.492646+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=4bb60171-35b7-4fe0-afd9-f4c43d4357b9 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:56:00.721576+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=2dee01f7-5392-40b5-b9d2-38178f32e698 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:56:02.052904+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=15afa6fc-8216-48f9-a637-92c82506b4ce fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:56:02.265575+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=998e5185-b367-4121-9bdc-5673d37deeff fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:57:27.796870+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=e753734d-79ed-4c36-8e6f-08e591edafee fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:57:28.036446+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=e0147f98-9f83-4c51-a6c8-cb3d9c46c47b fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:58:30.003002+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=00c1688f-740f-4cbf-9d0d-cc6c25d23cf4 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:58:30.226148+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=c7c59508-0d33-4e98-b2a3-4c8ebfd8529f fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:58:30.878029+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=ec7d5038-82eb-4c12-aed6-0488401f7a9e fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T03:58:31.085787+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=15f39eec-de96-48f0-8f6b-575cd688ba91 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T04:02:16.853379+00:00 heroku[worker.1]: State changed from crashed to starting
2017-07-27T04:02:21.100226+00:00 heroku[worker.1]: Starting process with command `node index.js`
2017-07-27T04:02:21.727262+00:00 heroku[worker.1]: State changed from starting to up
2017-07-27T04:02:23.099454+00:00 app[worker.1]: module.js:471
2017-07-27T04:02:23.099481+00:00 app[worker.1]:     throw err;
2017-07-27T04:02:23.099482+00:00 app[worker.1]:     ^
2017-07-27T04:02:23.099482+00:00 app[worker.1]: 
2017-07-27T04:02:23.099484+00:00 app[worker.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-07-27T04:02:23.099483+00:00 app[worker.1]: Error: Cannot find module '/app/index.js'
2017-07-27T04:02:23.099485+00:00 app[worker.1]:     at Function.Module._load (module.js:417:25)
2017-07-27T04:02:23.099485+00:00 app[worker.1]:     at Module.runMain (module.js:604:10)
2017-07-27T04:02:23.099486+00:00 app[worker.1]:     at run (bootstrap_node.js:389:7)
2017-07-27T04:02:23.099486+00:00 app[worker.1]:     at startup (bootstrap_node.js:149:9)
2017-07-27T04:02:23.099487+00:00 app[worker.1]:     at bootstrap_node.js:504:3
2017-07-27T04:02:23.189149+00:00 heroku[worker.1]: Process exited with status 1
2017-07-27T04:02:23.199937+00:00 heroku[worker.1]: State changed from up to crashed
2017-07-27T04:03:40.500129+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=e1058a8e-46a1-4372-a702-f616540f792a fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T04:03:40.730673+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=3ffc8109-d893-43fc-8478-132ef1744a3d fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T04:03:41.990804+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=hooptime.herokuapp.com request_id=fd31d62c-c0f9-4acc-b72c-3d80d1d0d362 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
2017-07-27T04:03:42.209388+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=hooptime.herokuapp.com request_id=5b07975b-ffe1-43e6-8d72-7acf905d4bf2 fwd="66.205.150.33" dyno= connect= service= status=503 bytes= protocol=https
macs-iMac:hooptime mac$ 

过程文件:

worker: node index.js

package.json:

        {
  "name": "hooptime",
  "description": "Our sample Node to Heroku app",
  "engines": { "node": "7.1.0"},
  "main": "server.js",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "~4.9.8"
  }
}

index.js:

     var express = require('express');
var bodyParser = require('body-parser');

var app = express();

app.set('port', (process.env.PORT || 8080));
app.use(express.static(__dirname + '/app'));
app.set('views', __dirname + '/app/parks/');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(bodyParser.json());

app.get('*', function(req, res){
    res.render('register.view.html');
});

app.listen(app.get('port'), function() {
});

【问题讨论】:

    标签: angularjs node.js heroku deployment production-environment


    【解决方案1】:

    在您的 Procfile 中,您将 worker 定义为

    worker: node index.js
    

    但是您的主文件名为 server.js,因此您应该将 Procfile 定义为

    worker: node server.js
    

    【讨论】:

    • 嗨@arpit 谢谢你的回复。我继续进行了更改,但是我的日志中仍然提到了另一个错误,指出:错误:找不到模块'/app/index.js'我正在从根项目路径运行应用程序,我可以确认那里是一个 index.js 文件。我已经用 index.js 中的代码更新了我的问题。还有其他想法吗?
    • 如果您的 Procfile 和 server.js 不在同一个目录中,那么您必须将相对路径放在 worker 中,我建议将文件重命名为 index.js
    • 再次感谢您的建议。我听取了您的建议: 1. 重命名服务器。 js --> index.js 2. 更新/移动 Procfile 和新重命名的 index.js 到项目目录的根目录 3. 压缩我的 package.json 我已经将我的新日志和文件添加到问题中,并添加了一个我的项目结构的屏幕截图。无论我将 index.js 移入还是移出 app 目录,我都会继续看到“找不到模块:/app/index.js”的错误。我已经通过heroku重新启动了应用程序,重新调整了worker,并将代码重新推送到heroku。想到其他解决方案了吗?
    • 应该是app/index.js,我认为你确实输入了/app/index.js,这可能是错误的
    猜你喜欢
    • 1970-01-01
    • 2021-03-13
    • 2014-07-16
    • 1970-01-01
    • 2017-12-05
    • 2021-08-29
    • 2021-11-25
    • 2012-10-30
    • 2020-11-30
    相关资源
    最近更新 更多