部署到heroku时,我的应用程序不断崩溃。我收到这个担心的应用程序错误主屏幕

时间:2018-07-19 18:13:15

标签: javascript angular typescript heroku npm

这是我的日志

2018-07-19T01:40:27.548845+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2018-07-19T01:40:27.548847+00:00 app[web.1]: at Module._compile (module.js:652:30)
2018-07-19T01:40:27.548850+00:00 app[web.1]: at Module.load (module.js:565:32)
2018-07-19T01:40:27.548848+00:00 app[web.1]: at Object.Module._extensions..js (module.js:663:10)
2018-07-19T01:40:27.548851+00:00 app[web.1]: at tryModuleLoad (module.js:505:12)
2018-07-19T01:40:27.548853+00:00 app[web.1]: at Function.Module._load (module.js:497:3)
2018-07-19T01:40:27.548854+00:00 app[web.1]: at Module.require (module.js:596:17)
2018-07-19T01:40:27.548856+00:00 app[web.1]: at require (internal/module.js:11:18)
2018-07-19T01:40:27.548858+00:00 app[web.1]: at Object.<anonymous> (/app/api/routes/users.js:4:16)
2018-07-19T01:40:27.548859+00:00 app[web.1]: at Module._compile (module.js:652:30)
2018-07-19T01:40:27.591620+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-07-19T01:40:27.591624+00:00 app[web.1]: npm ERR! errno 1
2018-07-19T01:40:27.592485+00:00 app[web.1]: npm ERR! main-accounting-app@1.0.0 start: `node app.js`
2018-07-19T01:40:27.592488+00:00 app[web.1]: npm ERR! Exit status 1
2018-07-19T01:40:27.595923+00:00 app[web.1]: npm ERR! Failed at the main-accounting-app@1.0.0 start script.
2018-07-19T01:40:27.592490+00:00 app[web.1]: npm ERR!
2018-07-19T01:40:27.596528+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-07-19T01:40:27.618466+00:00 app[web.1]:
2018-07-19T01:40:27.619407+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-07-19T01:40:27.619410+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-07-19T01_40_27_602Z-debug.log
2018-07-19T01:40:27.683715+00:00 heroku[web.1]: Process exited with status 1
2018-07-19T01:40:27.707660+00:00 heroku[web.1]: State changed from starting to crashed
2018-07-19T07:16:42.016935+00:00 heroku[web.1]: State changed from crashed to starting
2018-07-19T07:16:46.448819+00:00 heroku[web.1]: Starting process with command `npm start`
2018-07-19T07:16:49.016333+00:00 app[web.1]:
2018-07-19T07:16:49.016352+00:00 app[web.1]: > main-accounting-app@1.0.0 start /app
2018-07-19T07:16:49.016354+00:00 app[web.1]: > node app.js
2018-07-19T07:16:49.016355+00:00 app[web.1]:
2018-07-19T07:16:49.816284+00:00 app[web.1]: module.js:681
2018-07-19T07:16:49.816323+00:00 app[web.1]: return process.dlopen(module, path._makeLong(filename));
2018-07-19T07:16:49.816325+00:00 app[web.1]: ^
2018-07-19T07:16:49.816326+00:00 app[web.1]:
2018-07-19T07:16:49.816328+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2018-07-19T07:16:49.816330+00:00 app[web.1]: at Object.Module._extensions..node (module.js:681:18)
2018-07-19T07:16:49.816332+00:00 app[web.1]: at Module.load (module.js:565:32)
2018-07-19T07:16:49.816333+00:00 app[web.1]: at tryModuleLoad (module.js:505:12)
2018-07-19T07:16:49.816335+00:00 app[web.1]: at Function.Module._load (module.js:497:3)
2018-07-19T07:16:49.816336+00:00 app[web.1]: at Module.require (module.js:596:17)
2018-07-19T07:16:49.816338+00:00 app[web.1]: at require (internal/module.js:11:18)
2018-07-19T07:16:49.816339+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2018-07-19T07:16:49.816341+00:00 app[web.1]: at Module._compile (module.js:652:30)
2018-07-19T07:16:49.816342+00:00 app[web.1]: at Object.Module._extensions..js (module.js:663:10)
2018-07-19T07:16:49.816344+00:00 app[web.1]: at Module.load (module.js:565:32)
2018-07-19T07:16:49.816345+00:00 app[web.1]: at tryModuleLoad (module.js:505:12)
2018-07-19T07:16:49.816347+00:00 app[web.1]: at Function.Module._load (module.js:497:3)
2018-07-19T07:16:49.816348+00:00 app[web.1]: at Module.require (module.js:596:17)
2018-07-19T07:16:49.816350+00:00 app[web.1]: at require (internal/module.js:11:18)
2018-07-19T07:16:49.816351+00:00 app[web.1]: at Object.<anonymous> (/app/api/routes/users.js:4:16)
2018-07-19T07:16:49.816353+00:00 app[web.1]: at Module._compile (module.js:652:30)
2018-07-19T07:16:49.836368+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-07-19T07:16:49.836844+00:00 app[web.1]: npm ERR! errno 1
2018-07-19T07:16:49.838607+00:00 app[web.1]: npm ERR! main-accounting-app@1.0.0 start: `node app.js`
2018-07-19T07:16:49.838827+00:00 app[web.1]: npm ERR! Exit status 1
2018-07-19T07:16:49.839121+00:00 app[web.1]: npm ERR!
2018-07-19T07:16:49.839354+00:00 app[web.1]: npm ERR! Failed at the main-accounting-app@1.0.0 start script.
2018-07-19T07:16:49.839577+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-07-19T07:16:49.847895+00:00 app[web.1]:
2018-07-19T07:16:49.848144+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-07-19T07:16:49.848330+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-07-19T07_16_49_841Z-debug.log
2018-07-19T07:16:49.905428+00:00 heroku[web.1]: Process exited with status 1
2018-07-19T07:16:49.993589+00:00 heroku[web.1]: State changed from starting to crashed
2018-07-19T13:08:57.597790+00:00 heroku[web.1]: State changed from crashed to starting
2018-07-19T13:09:01.146666+00:00 heroku[web.1]: Starting process with command `npm start`
2018-07-19T13:09:04.282556+00:00 app[web.1]:
2018-07-19T13:09:04.282604+00:00 app[web.1]: > main-accounting-app@1.0.0 start /app
2018-07-19T13:09:04.282606+00:00 app[web.1]: > node app.js
2018-07-19T13:09:04.282608+00:00 app[web.1]:
2018-07-19T13:09:05.386813+00:00 app[web.1]: module.js:681
2018-07-19T13:09:05.386865+00:00 app[web.1]: return process.dlopen(module, path._makeLong(filename));
2018-07-19T13:09:05.386867+00:00 app[web.1]: ^
2018-07-19T13:09:05.386869+00:00 app[web.1]:
2018-07-19T13:09:05.386872+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2018-07-19T13:09:05.386873+00:00 app[web.1]: at Object.Module._extensions..node (module.js:681:18)
2018-07-19T13:09:05.386875+00:00 app[web.1]: at Module.load (module.js:565:32)
2018-07-19T13:09:05.386877+00:00 app[web.1]: at tryModuleLoad (module.js:505:12)
2018-07-19T13:09:05.386878+00:00 app[web.1]: at Function.Module._load (module.js:497:3)
2018-07-19T13:09:05.386880+00:00 app[web.1]: at Module.require (module.js:596:17)
2018-07-19T13:09:05.386881+00:00 app[web.1]: at require (internal/module.js:11:18)
2018-07-19T13:09:05.386883+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2018-07-19T13:09:05.386885+00:00 app[web.1]: at Module._compile (module.js:652:30)
2018-07-19T13:09:05.386886+00:00 app[web.1]: at Object.Module._extensions..js (module.js:663:10)
2018-07-19T13:09:05.386888+00:00 app[web.1]: at Module.load (module.js:565:32)
2018-07-19T13:09:05.386889+00:00 app[web.1]: at tryModuleLoad (module.js:505:12)
2018-07-19T13:09:05.386891+00:00 app[web.1]: at Function.Module._load (module.js:497:3)
2018-07-19T13:09:05.386892+00:00 app[web.1]: at Module.require (module.js:596:17)
2018-07-19T13:09:05.386894+00:00 app[web.1]: at require (internal/module.js:11:18)
2018-07-19T13:09:05.386895+00:00 app[web.1]: at Object.<anonymous> (/app/api/routes/users.js:4:16)
2018-07-19T13:09:05.386897+00:00 app[web.1]: at Module._compile (module.js:652:30)
2018-07-19T13:09:05.397833+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-07-19T13:09:05.398435+00:00 app[web.1]: npm ERR! errno 1
2018-07-19T13:09:05.400199+00:00 app[web.1]: npm ERR! main-accounting-app@1.0.0 start: `node app.js`
2018-07-19T13:09:05.400493+00:00 app[web.1]: npm ERR! Exit status 1
2018-07-19T13:09:05.400842+00:00 app[web.1]: npm ERR!
2018-07-19T13:09:05.401114+00:00 app[web.1]: npm ERR! Failed at the main-accounting-app@1.0.0 start script.
2018-07-19T13:09:05.401381+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-07-19T13:09:05.408887+00:00 app[web.1]:
2018-07-19T13:09:05.409196+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-07-19T13:09:05.409421+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-07-19T13_09_05_403Z-debug.log
2018-07-19T13:09:05.488426+00:00 heroku[web.1]: Process exited with status 1
2018-07-19T13:09:05.510644+00:00 heroku[web.1]: State changed from starting to crashed
PS C:\Users\USER\Documents\aaa-PROJECTS\Main-accounting-app>

这是我的procfile

web: node app.js

这是我的appjs

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const mongoose = require('mongoose');
const cors = require('cors');
const bodyParser = require('body-parser');


var indexRouter = require('./api/routes/index');
var usersRouter = require('./api/routes/users');

mongoose.connect('mongodb://xxx:xxx.mlab.com:39921/demobusinesshub',{
    // mongodb://localhost:27017/testbusinesshub
    // mongodb://xxx:xxx.mlab.com:39921/demobusinesshub
}).then(c => console.log('connected to db'))
.catch(c => console.log('connection to db error'))

var app = express();
app.use(cors());

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// bodyparser

app.use(bodyParser.json());

app.use('/', indexRouter);
app.use('/users', usersRouter);

const port = process.env.PORT || 3000;
const host = '0.0.0.0';

app.listen(port, host, ()=>{
    console.log('Server started on port '+ port);
});
module.exports = app;

这是我的包json

{
  "name": "main-accounting-app",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app"
  },

  "author": "Sunmola Ayokunle",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^2.0.1",
    "body-parser": "^1.18.3",
    "cookie-parser": "~1.4.3",
    "cors": "^2.8.4",
    "debug": "~2.6.9",
    "express": "~4.16.0",
    "http-errors": "~1.6.2",
    "jsonwebtoken": "^8.3.0",
    "mongoose": "^5.1.6",
    "morgan": "~1.9.0"
  }
}

以及我的角度服务的身份验证文件中

return this.http.post('' + this.domain + 'users/register', newUser, {headers: headers}).pipe(map(res => res.json()));

生产中的位置this.domain =''//(一个空字符串)

所以我不明白问题出在哪里,我从字面上搜索了网络,并被告知要检查端口等,我已经做了所有这些事情。在这个阶段我真的很困惑,我不知道该做什么。 我也已经在我的角度终端中进行了构建,并将其捆绑到我的快速应用程序的公用文件夹中。使用heroku本地作品运行此文件,不会出现任何错误。也可以在我的普通本地服务器上运行它

1 个答案:

答案 0 :(得分:0)

这个问题的答案:https://pastebin.com/3bqTbHsv在stackoverflow上,问题是您在Windows机器上安装了模块 bcrypt ,而heroku机器是linux,并且将该模块推到了heroku机器上, bcrypt 依赖项将不起作用。

要修复此问题,请删除heroku机器上的 node_modules 文件夹,然后将.gitignore文件添加到您的项目中,并在文件中添加以下行:

  

node_modules

然后运行: git add。并推送到heroku master。 因此heroku机器会自动安装依赖项,包括Linux的 bcrypt