将Node.js应用程序部署到Heroku的应用程序错误

时间:2015-11-10 05:02:38

标签: node.js heroku deployment web-deployment

我是新手将Github项目部署到Heroku。到目前为止,我已成功将我的应用程序连接到Heroku并已部署。该项目在我的本地机器上运行良好。但是,当我尝试启动我的应用程序的heroku网站时,它给了我这个错误:

  

"应用程序中发生错误,您的页面无法执行   提供服务。请稍后再试。

     

如果您是应用程序所有者,请查看日志以获取详细信息。"

这是我的heroku日志,我无法理解。

2015-11-10T04:33:10.538175+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=af3a9061-1b8f-47fe-9e2e-eafa624f2712 fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:33:10.649481+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=compasss.herokuapp.com request_id=e8fc1b43-f629-4e38-85c9-808d731e852e fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:33:11.334843+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=149ffc6c-8a57-475c-9f64-5224bcf72bfd fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:33:12.207897+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=4585d320-5d3b-43a0-ab85-a84f9734e373 fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:35:18.757410+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=compasss.herokuapp.com request_id=1d59ddd7-ff62-4b01-8b3a-df450fac5ba5 fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:35:19.737947+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=2f8f9bc8-8299-4da9-bdad-eed9fa537573 fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:35:19.503853+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=77870378-cde5-48e2-b4d2-e93526b1e10d fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:41:09.087924+00:00 heroku[api]: Deploy 5c325e8 by myemail@gmail.com
2015-11-10T04:41:09.087924+00:00 heroku[api]: Release v6 created by myemail@gmail.com
2015-11-10T04:41:09.271289+00:00 heroku[slug-compiler]: Slug compilation started
2015-11-10T04:41:09.271300+00:00 heroku[slug-compiler]: Slug compilation finished
2015-11-10T04:41:11.469002+00:00 heroku[web.1]: State changed from crashed to starting
2015-11-10T04:41:12.469938+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-11-10T04:41:14.322786+00:00 app[web.1]: module.js:339
2015-11-10T04:41:14.322794+00:00 app[web.1]:     throw err;
2015-11-10T04:41:14.322795+00:00 app[web.1]:     ^
2015-11-10T04:41:14.322796+00:00 app[web.1]:
2015-11-10T04:41:14.322797+00:00 app[web.1]: Error: Cannot find module 'express3-handlebars'
2015-11-10T04:41:14.322797+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:337:15)
2015-11-10T04:41:14.322798+00:00 app[web.1]:     at Function.Module._load (module.js:287:25)
2015-11-10T04:41:14.322799+00:00 app[web.1]:     at Module.require (module.js:366:17)
2015-11-10T04:41:14.322799+00:00 app[web.1]:     at require (module.js:385:17)
2015-11-10T04:41:14.322800+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:6:18)
2015-11-10T04:41:14.322800+00:00 app[web.1]:     at Module._compile (module.js:425:26)
2015-11-10T04:41:14.322801+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:432:10)
2015-11-10T04:41:14.322802+00:00 app[web.1]:     at Module.load (module.js:356:32)
2015-11-10T04:41:14.322802+00:00 app[web.1]:     at Function.Module._load (module.js:311:12)
2015-11-10T04:41:14.322803+00:00 app[web.1]:     at Function.Module.runMain (module.js:457:10)
2015-11-10T04:41:15.124877+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-10T04:41:15.116760+00:00 heroku[web.1]: Process exited with status 1
2015-11-10T04:44:48.813133+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=compasss.herokuapp.com request_id=81fddfea-92e6-4c64-91aa-ec5d076fb8e6 fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:44:49.590449+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=efa1b5fc-5a1e-4b31-acef-5a1025e8c99d fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:44:49.955648+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=4af0cf53-ea53-4361-a5d2-6a3efc51a62f fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:51:46.883632+00:00 heroku[api]: Deploy b0f6afe by myemail@gmail.com
2015-11-10T04:51:46.883703+00:00 heroku[api]: Release v7 created by myemail@gmail.com
2015-11-10T04:51:46.979243+00:00 heroku[web.1]: State changed from crashed to starting
2015-11-10T04:51:47.041376+00:00 heroku[slug-compiler]: Slug compilation started
2015-11-10T04:51:47.041386+00:00 heroku[slug-compiler]: Slug compilation finished
2015-11-10T04:51:48.436794+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-11-10T04:51:50.436732+00:00 app[web.1]: module.js:339
2015-11-10T04:51:50.436759+00:00 app[web.1]:     at Function.Module._load (module.js:287:25)
2015-11-10T04:51:50.436761+00:00 app[web.1]:     at Module._compile (module.js:425:26)
2015-11-10T04:51:50.436754+00:00 app[web.1]:     throw err;
2015-11-10T04:51:50.436756+00:00 app[web.1]:
2015-11-10T04:51:50.436763+00:00 app[web.1]:     at Function.Module._load (module.js:311:12)
2015-11-10T04:51:50.436755+00:00 app[web.1]:     ^
2015-11-10T04:51:50.436759+00:00 app[web.1]:     at Module.require (module.js:366:17)
2015-11-10T04:51:50.436757+00:00 app[web.1]: Error: Cannot find module 'express3-handlebars'
2015-11-10T04:51:50.436758+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:337:15)
2015-11-10T04:51:50.436762+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:432:10)
2015-11-10T04:51:50.436764+00:00 app[web.1]:     at Function.Module.runMain (module.js:457:10)
2015-11-10T04:51:50.436760+00:00 app[web.1]:     at require (module.js:385:17)
2015-11-10T04:51:50.436760+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:6:18)
2015-11-10T04:51:50.436762+00:00 app[web.1]:     at Module.load (module.js:356:32)
2015-11-10T04:51:51.157210+00:00 heroku[web.1]: Process exited with status 1
2015-11-10T04:51:52.735586+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-11-10T04:51:55.545983+00:00 app[web.1]: module.js:339
2015-11-10T04:51:55.545998+00:00 app[web.1]:     throw err;
2015-11-10T04:51:55.545999+00:00 app[web.1]:     ^
2015-11-10T04:51:55.545999+00:00 app[web.1]:
2015-11-10T04:51:55.546001+00:00 app[web.1]: Error: Cannot find module 'express3-handlebars'
2015-11-10T04:51:55.546002+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:337:15)
2015-11-10T04:51:55.546002+00:00 app[web.1]:     at Function.Module._load (module.js:287:25)
2015-11-10T04:51:55.546003+00:00 app[web.1]:     at Module.require (module.js:366:17)
2015-11-10T04:51:55.546003+00:00 app[web.1]:     at require (module.js:385:17)
2015-11-10T04:51:55.546004+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:6:18)
2015-11-10T04:51:55.546004+00:00 app[web.1]:     at Module._compile (module.js:425:26)
2015-11-10T04:51:55.546005+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:432:10)
2015-11-10T04:51:55.546006+00:00 app[web.1]:     at Module.load (module.js:356:32)
2015-11-10T04:51:55.546007+00:00 app[web.1]:     at Function.Module.runMain (module.js:457:10)
2015-11-10T04:51:55.546006+00:00 app[web.1]:     at Function.Module._load (module.js:311:12)
2015-11-10T04:51:51.172084+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-10T04:51:51.173050+00:00 heroku[web.1]: State changed from crashed to starting
2015-11-10T04:51:56.492216+00:00 heroku[web.1]: Process exited with status 1
2015-11-10T04:51:56.506380+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-10T04:53:27.766915+00:00 heroku[api]: Deploy 15c64ba by myemail@gmail.com
2015-11-10T04:53:27.766915+00:00 heroku[api]: Release v8 created by myemail@gmail.com
2015-11-10T04:53:27.910792+00:00 heroku[slug-compiler]: Slug compilation started
2015-11-10T04:53:27.910801+00:00 heroku[slug-compiler]: Slug compilation finished
2015-11-10T04:53:27.921730+00:00 heroku[web.1]: State changed from crashed to starting
2015-11-10T04:53:29.221014+00:00 heroku[web.1]: Starting process with command `node app.js`
2015-11-10T04:53:31.264123+00:00 app[web.1]: module.js:339
2015-11-10T04:53:31.264132+00:00 app[web.1]:     throw err;
2015-11-10T04:53:31.264133+00:00 app[web.1]:     ^
2015-11-10T04:53:31.264134+00:00 app[web.1]:
2015-11-10T04:53:31.264135+00:00 app[web.1]: Error: Cannot find module 'express3-handlebars'
2015-11-10T04:53:31.264136+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:337:15)
2015-11-10T04:53:31.264136+00:00 app[web.1]:     at Function.Module._load (module.js:287:25)
2015-11-10T04:53:31.264137+00:00 app[web.1]:     at Module.require (module.js:366:17)
2015-11-10T04:53:31.264138+00:00 app[web.1]:     at require (module.js:385:17)
2015-11-10T04:53:31.264138+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:6:18)
2015-11-10T04:53:31.264139+00:00 app[web.1]:     at Module._compile (module.js:425:26)
2015-11-10T04:53:31.264140+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:432:10)
2015-11-10T04:53:31.264140+00:00 app[web.1]:     at Module.load (module.js:356:32)
2015-11-10T04:53:31.264141+00:00 app[web.1]:     at Function.Module._load (module.js:311:12)
2015-11-10T04:53:31.264141+00:00 app[web.1]:     at Function.Module.runMain (module.js:457:10)
2015-11-10T04:53:31.969583+00:00 heroku[web.1]: Process exited with status 1
2015-11-10T04:53:31.989169+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-10T04:54:44.812224+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=compasss.herokuapp.com request_id=a508a64d-8a85-4d09-a610-67ef57854186 fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:54:45.733283+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=1a312b38-8793-41fa-9a77-2d2e7f0c63f2 fwd="138.110.234.184" dyno= connect= service= status=503 bytes=
2015-11-10T04:54:45.461863+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=compasss.herokuapp.com request_id=47d48dc9-3e16-4b49-8b25-7b56a8b3ccad fwd="138.110.234.184" dyno= connect= service= status=503 bytes=

我认为错误可能是由于我如何设置我的路线。这是我的app.js,我指定了我的路线:

var express = require('express');
var app = express();
var http = require('http').Server(app);

// set up handlebars view engine
var handlebars = require('express3-handlebars')
  .create({ defaultLayout:'main' });
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');

http.listen(process.env.PORT || 3000, function(){
  console.log('listening on', http.address().port);
})

// Home Page
app.get('/', function(req, res){
  res.render('home');
});

// About Page
app.get('/about', function(req, res){
  res.render('about');
});

// 404 catch-all handler (middleware)
app.use(function(req, res){
  res.status(404);
  res.render('404');
});

// 500 error handler (middleware)
app.use(function(req, res){
  console.error(err.stack);
  res.status(500);
  res.render('500');
});

app.listen(app.get('port'), function(){
console.log( 'Express started on http://localhost:' +
app.get('port') + '; press Ctrl-C to terminate.' );
});

这是我的package.json

{
  "name": "Compass",
  "version": "1.0.0",
  "description": "Independent Study Application",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
  },
  "author": "Thao Bach",
  "license": "ISC",
  "dependencies": {
    "express": "^4.13.3",
    "express-handlebars": "^2.0.1",
    "mongodb": "^2.0.46",
    "monk": "^1.0.1"
  },
  "devDependencies": {
    "archiver": "^0.15.1",
    "chai": "^3.3.0",
    "fs-extra": "^0.24.0",
    "mocha": "^2.3.3"
  }
}

1 个答案:

答案 0 :(得分:1)

您的express3-handlebars中很可能没有提到npm依赖项package.json,或者在package.json文件中将其称为开发依赖项。

另外,在你正在使用的app.js中

var handlebars = require('express3-handlebars')
  .create({ defaultLayout:'main' });

您可能希望将require语句更改为指向express-handlebars或将express3-handlebars包含为依赖