无法在Heroku上成功执行Node.js应用程序(每次崩溃)

时间:2012-04-27 20:38:31

标签: node.js heroku foreman

我试图在Heroku上基本按照他们的说明在一起放置一个示例node.js应用程序:https://devcenter.heroku.com/articles/nodejs

应用程序在foreman start本地运行良好,但是,每次部署应用程序时,它都会崩溃。 我做错了什么?

我的Procfile包含:

web: node web.js

我的package.json包含:

{
  "name": "testapp",
  "version": "0.0.1",
  "engines": {
      "node": "0.6.15"
    , "npm": "1.1.9"    
  }
  , "dependencies": {
    "tower": "0.4.0-12"
  }
}

我的web.js包含:

var express = require('express');

var app = express.createServer(express.logger());

app.get('/', function(request, response) {
  response.send('Hello World!');
});

var port = process.env.PORT || 3000;
app.listen(port, function() {
  console.log("Listening on " + port);
});

该应用程序部署并启动,但每次都崩溃。我从应用程序看到的日志输出是:

2012-04-27T20:21:31+00:00 heroku[web.1]: State changed from created to starting
2012-04-27T20:21:37+00:00 heroku[web.1]: Starting process with command `node web.js`
2012-04-27T20:21:38+00:00 app[web.1]: 
2012-04-27T20:21:38+00:00 app[web.1]: node.js:201
2012-04-27T20:21:38+00:00 app[web.1]:         throw e; // process.nextTick error, or 'error' event on first tick
2012-04-27T20:21:38+00:00 app[web.1]:               ^
2012-04-27T20:21:38+00:00 app[web.1]: Error: Cannot find module 'express'
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._resolveFilename (module.js:332:11)
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._load (module.js:279:25)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module.require (module.js:354:17)
2012-04-27T20:21:38+00:00 app[web.1]:     at require (module.js:370:17)
2012-04-27T20:21:38+00:00 app[web.1]:     at Object.<anonymous> (/app/web.js:1:77)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module._compile (module.js:441:26)
2012-04-27T20:21:38+00:00 app[web.1]:     at Object..js (module.js:459:10)
2012-04-27T20:21:38+00:00 app[web.1]:     at Module.load (module.js:348:31)
2012-04-27T20:21:38+00:00 app[web.1]:     at Function._load (module.js:308:12)
2012-04-27T20:21:38+00:00 app[web.1]:     at Array.0 (module.js:479:10)
2012-04-27T20:21:39+00:00 heroku[web.1]: Process exited with status 1
2012-04-27T20:21:40+00:00 heroku[web.1]: State changed from starting to crashed
2012-04-27T20:30:01+00:00 heroku[router]: Error H10 (App crashed) -> GET testapp.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=

3 个答案:

答案 0 :(得分:9)

您的web.js中似乎需要表达,那么为什么不向依赖项添加express?您的本地副本可能已经快速安装,这就是您没有收到任何错误的原因。 Tower可能需要express,但是,你不能直接访问express,它是塔目录中的子模块,而不是你的app目录。

答案 1 :(得分:0)

过去这是npm版本的问题。我建议升级到最新版本并重新安装至少快递。

答案 2 :(得分:0)

检查您是否在package.json中的devDependencies下没有明确定义。如果这样做,即使运行npm install express --save也不会将其移动到依赖项。

我在使用vue-cli创建的Vue.js项目中遇到了这个问题,它在devDependencies下添加了快速dep。