无法在 Heroku 上部署 Node.js 应用程序

马特·坎贝尔

我知道这与这个人在这里提出的问题相同,但我还不能发表评论,因为我没有 50 声望。

我尝试按照该问题提供的答案进行操作,但仍然存在与 Heroku 无法找到“express”相同的错误。但是,express 出现在我的 package.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 [email protected]
2017-10-30T13:22:23.512366+00:00 app[api]: Release v1 created by user [email protected]
2017-10-30T13:22:23.607220+00:00 app[api]: Release v2 created by user [email protected]
2017-10-30T13:22:23.607220+00:00 app[api]: Enable Logplex by user [email protected]
2017-10-30T13:28:32.000000+00:00 app[api]: Build started by user [email protected]
2017-10-30T13:29:04.387219+00:00 app[api]: Release v3 created by user [email protected]
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 [email protected]
2017-10-30T13:29:04.387219+00:00 app[api]: Deploy dc2a122a by user [email protected]
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
赛义德

尝试将引擎放在 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": ""
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Sails.js应用程序无法在Heroku上部署

node.js应用程序可在本地运行,但在heroku上部署时会崩溃

尝试在Heroku上部署Node.js / Express / Socket.io应用程序时出现应用程序错误

无法在Heroku上部署Node.js-MongoDB项目

在Heroku上部署Node.js无法提供静态文件

无法在 Node JS 服务器上部署 React 应用程序

无法看到在Heroku上部署Ruby on Rails应用程序?

推送被拒绝,在 heroku 中部署时无法编译 Node.js 应用程序

Node.js应用程序在本地主机上运行良好,但在Heroku上部署时显示错误

Node.js应用程序在Heroku中部署

无法在heroku上托管node.js应用程序。正在显示应用程序错误

由于硬编码的端口号,无法将node.js应用程序部署到heroku

无法在Heroku上部署基本的Rails应用

在Heroku上部署Fb应用程序

在 Heroku 上部署 React 应用程序

无法在Heroku上部署

需要在heroku上部署node.js + mongoDB应用程序,但是他们要求提供安装附加组件的信用卡

刷新页面后,无法在heroku上部署Vue + Webpack应用程序

无法在 Heroku 上部署 Streamlit 应用程序 - 缺少 libgcc_s.so.1

为什么我的简单 Spring Boot 应用程序无法在 Heroku 上部署?

在Heroku上部署Node.js应用时出现403错误

在 Heroku 上部署 Express 应用程序错误:找不到模块“/app/server.js”

部署:将Angular 2 / Node.js应用程序部署到Heroku

无法在Websphere上部署应用程序

Heroku:找不到该应用程序/推送被拒绝,无法编译 Node.js 应用程序

如何在Node.js服务器上部署Vue.js应用程序

如何将Typescript Node.js应用程序部署到Heroku?

如何在Heroku上使用Neutrino部署Node.js应用程序

使用Heroku部署Node.js应用程序时公共目录出现问题