【发布时间】:2018-04-11 12:58:41
【问题描述】:
我知道这与这个人here 的问题相同,但我还不能发表评论,因为我没有 50 声望。
我尝试按照问题提供的答案进行操作,但仍然存在与 Heroku 无法找到“express”相同的错误。但是,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
【问题讨论】:
-
尝试将
"engines": {"node": "6.11.2","npm": "5.5.1"},放在依赖对象之外 -
在本地/开发机器上....擦除 node-modules 目录,然后在那里重做 'npm install' 到 'heroku local' 并查看本地结果....
-
@Syed 太棒了!那行得通!我一直在到处寻找解决方案,这就是问题所在。你想回答这个问题以便我接受吗?