无法在Heroku

时间:2017-10-30 13:57:29

标签: node.js heroku

我知道这个问题与这个家伙有here同样的问题,但我还不能发表评论,因为我没有50个声誉。

我尝试按照提供的问题的答案,但仍然有相同的错误,Heroku无法找到'表达'。但是,express出现在packages.json中的依赖项中,并且都在本地正确运行。我也是" npm install express --save"以及使用-g标志尝试它。我还能做些什么让Heroku找到'表达'?

我的 package.json 包含:

{
  "name": "spark",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "MAXXtreme",
  "license": "MIT",
  "dependencies": {
    "ejs": "^2.5.7",
    "engines": {
      "node": "6.11.2",
      "npm": "5.5.1"
    },
    "express": "^4.16.2",
    "express-fileupload": "^0.3.0",
    "express-messages": "^1.0.1",
    "express-session": "^1.15.6",
    "express-validator": "^4.3.0",
    "mongoose": "^4.12.4"
  },
  "devDependencies": {},
  "description": ""
}

我的 app.js 包含:

var express = require('express');
var mongoose = require('mongoose');
var config = require('./config/database');

// Connect to db
mongoose.connect(config.database);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
  console.log('Connected to MongoDB');
});

// Init app
var app = express();

// View engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

// Set public folder
app.use(express.static(path.join(__dirname, 'public')));

// Start the server
var port = process.env.PORT || 3000;
app.listen(port, function () {
    console.log('Server started on port ' + port);
});

以下是来自Heroku CLI的日志

2017-10-30T13:22:23.512366+00:00 app[api]: Initial release by user matt@steeltechmfg.com
2017-10-30T13:22:23.512366+00:00 app[api]: Release v1 created by user matt@steeltechmfg.com
2017-10-30T13:22:23.607220+00:00 app[api]: Release v2 created by user matt@steeltechmfg.com
2017-10-30T13:22:23.607220+00:00 app[api]: Enable Logplex by user matt@steeltechmfg.com
2017-10-30T13:28:32.000000+00:00 app[api]: Build started by user matt@steeltechmfg.com
2017-10-30T13:29:04.387219+00:00 app[api]: Release v3 created by user matt@steeltechmfg.com
2017-10-30T13:28:32.000000+00:00 app[api]: Build succeeded
2017-10-30T13:29:04.401658+00:00 app[api]: Scaled to web@1:Free by user matt@steeltechmfg.com
2017-10-30T13:29:04.387219+00:00 app[api]: Deploy dc2a122a by user matt@steeltechmfg.com
2017-10-30T13:29:06.586186+00:00 heroku[web.1]: Starting process with command `node --debug=5858 app.js`
2017-10-30T13:29:08.458266+00:00 app[web.1]: Debugger listening on [::]:5858
2017-10-30T13:29:08.521127+00:00 app[web.1]: module.js:471
2017-10-30T13:29:08.521129+00:00 app[web.1]:     throw err;
2017-10-30T13:29:08.521130+00:00 app[web.1]:     ^
2017-10-30T13:29:08.521131+00:00 app[web.1]:
2017-10-30T13:29:08.521131+00:00 app[web.1]: Error: Cannot find module 'express'
2017-10-30T13:29:08.521132+00:00 app[web.1]:     at Function.Module._resolveFilename (module.js:469:15)
2017-10-30T13:29:08.521133+00:00 app[web.1]:     at Function.Module._load (module.js:417:25)
2017-10-30T13:29:08.521134+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-10-30T13:29:08.521134+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-10-30T13:29:08.521135+00:00 app[web.1]:     at Object.<anonymous> (/app/app.js:1:77)
2017-10-30T13:29:08.521135+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-10-30T13:29:08.521136+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-10-30T13:29:08.521136+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-10-30T13:29:08.521137+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-10-30T13:29:08.521138+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-10-30T13:29:08.617580+00:00 heroku[web.1]: State changed from starting to crashed
2017-10-30T13:29:08.620539+00:00 heroku[web.1]: State changed from crashed to starting
2017-10-30T13:29:08.598008+00:00 heroku[web.1]: Process exited with status 1

1 个答案:

答案 0 :(得分:1)

尝试在package.json

中的依赖项之外放置引擎
{
  "name": "spark",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "MAXXtreme",
  "license": "MIT",
  "engines": {
    "node": "6.11.2",
    "npm": "5.5.1"
  },
  "dependencies": {
    "ejs": "^2.5.7",
    "express": "^4.16.2",
    "express-fileupload": "^0.3.0",
    "express-messages": "^1.0.1",
    "express-session": "^1.15.6",
    "express-validator": "^4.3.0",
    "mongoose": "^4.12.4"
  },
  "devDependencies": {},
  "description": ""
}