1

My server runs perfectly when I test it locally. However, deploying it to heroku shows the following error:

moh@ start /app
2017-05-01T08:04:40.867324+00:00 app[web.1]: > node server.js
2017-05-01T08:04:40.867324+00:00 app[web.1]: 
2017-05-01T08:04:41.360564+00:00 app[web.1]: module.js:597
2017-05-01T08:04:41.360579+00:00 app[web.1]:   return process.dlopen(module, path._makeLong(filename));
2017-05-01T08:04:41.360580+00:00 app[web.1]:                  ^
2017-05-01T08:04:41.360581+00:00 app[web.1]: 
2017-05-01T08:04:41.360582+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2017-05-01T08:04:41.360582+00:00 app[web.1]:     at Error (native)
2017-05-01T08:04:41.360583+00:00 app[web.1]:     at Object.Module._extensions..node (module.js:597:18)
2017-05-01T08:04:41.360584+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-05-01T08:04:41.360585+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-05-01T08:04:41.360585+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-05-01T08:04:41.360586+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-05-01T08:04:41.360586+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-05-01T08:04:41.360587+00:00 app[web.1]:     at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2017-05-01T08:04:41.360588+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-05-01T08:04:41.360588+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-05-01T08:04:41.360589+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-05-01T08:04:41.360590+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-05-01T08:04:41.360590+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-05-01T08:04:41.360591+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-05-01T08:04:41.360592+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-05-01T08:04:41.360592+00:00 app[web.1]:     at Object.<anonymous> (/app/usersDetailsRoutes.js:3:14)
2017-05-01T08:04:41.370305+00:00 app[web.1]: 
2017-05-01T08:04:41.378189+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-05-01T08:04:41.378466+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-05-01T08:04:41.378704+00:00 app[web.1]: npm ERR! node v6.10.2
2017-05-01T08:04:41.378844+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-05-01T08:04:41.378970+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-05-01T08:04:41.379105+00:00 app[web.1]: npm ERR! moh@ start: `node server.js`
2017-05-01T08:04:41.379189+00:00 app[web.1]: npm ERR! Exit status 1
2017-05-01T08:04:41.379285+00:00 app[web.1]: npm ERR! 
2017-05-01T08:04:41.379382+00:00 app[web.1]: npm ERR! Failed at the moh@ start script 'node server.js'.
2017-05-01T08:04:41.379537+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-05-01T08:04:41.379634+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the moh package,
2017-05-01T08:04:41.379743+00:00 app[web.1]: npm ERR! not with npm itself.
2017-05-01T08:04:41.379844+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-05-01T08:04:41.379931+00:00 app[web.1]: npm ERR!     node server.js
2017-05-01T08:04:41.380018+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-05-01T08:04:41.380103+00:00 app[web.1]: npm ERR!     npm bugs moh
2017-05-01T08:04:41.380233+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-05-01T08:04:41.380389+00:00 app[web.1]: npm ERR!     npm owner ls moh
2017-05-01T08:04:41.380459+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-05-01T08:04:41.384059+00:00 app[web.1]: 
2017-05-01T08:04:41.384227+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-05-01T08:04:41.384288+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-05-01T08:04:41.507958+00:00 heroku[web.1]: State changed from starting to crashed
2017-05-01T08:04:41.509045+00:00 heroku[web.1]: State changed from crashed to starting
2017-05-01T08:04:41.492959+00:00 heroku[web.1]: Process exited with status 1
2017-05-01T08:04:43.465939+00:00 heroku[web.1]: Starting process with command `npm start`
2017-05-01T08:04:45.782290+00:00 app[web.1]: 
2017-05-01T08:04:45.782305+00:00 app[web.1]: > moh@ start /app
2017-05-01T08:04:45.782306+00:00 app[web.1]: > node server.js
2017-05-01T08:04:45.782307+00:00 app[web.1]: 
2017-05-01T08:04:46.242097+00:00 app[web.1]: module.js:597
2017-05-01T08:04:46.242120+00:00 app[web.1]:   return process.dlopen(module, path._makeLong(filename));
2017-05-01T08:04:46.242121+00:00 app[web.1]:                  ^
2017-05-01T08:04:46.242122+00:00 app[web.1]: 
2017-05-01T08:04:46.242123+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2017-05-01T08:04:46.242123+00:00 app[web.1]:     at Error (native)
2017-05-01T08:04:46.242124+00:00 app[web.1]:     at Object.Module._extensions..node (module.js:597:18)
2017-05-01T08:04:46.242125+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-05-01T08:04:46.242125+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-05-01T08:04:46.242126+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-05-01T08:04:46.242127+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-05-01T08:04:46.242127+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-05-01T08:04:46.242128+00:00 app[web.1]:     at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2017-05-01T08:04:46.242128+00:00 app[web.1]:     at Module._compile (module.js:570:32)
2017-05-01T08:04:46.242129+00:00 app[web.1]:     at Object.Module._extensions..js (module.js:579:10)
2017-05-01T08:04:46.242130+00:00 app[web.1]:     at Module.load (module.js:487:32)
2017-05-01T08:04:46.242130+00:00 app[web.1]:     at tryModuleLoad (module.js:446:12)
2017-05-01T08:04:46.242131+00:00 app[web.1]:     at Function.Module._load (module.js:438:3)
2017-05-01T08:04:46.242132+00:00 app[web.1]:     at Module.require (module.js:497:17)
2017-05-01T08:04:46.242132+00:00 app[web.1]:     at require (internal/module.js:20:19)
2017-05-01T08:04:46.242133+00:00 app[web.1]:     at Object.<anonymous> (/app/usersDetailsRoutes.js:3:14)
2017-05-01T08:04:46.250340+00:00 app[web.1]: 
2017-05-01T08:04:46.257941+00:00 app[web.1]: npm ERR! Linux 3.13.0-112-generic
2017-05-01T08:04:46.258139+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2017-05-01T08:04:46.258285+00:00 app[web.1]: npm ERR! node v6.10.2
2017-05-01T08:04:46.258630+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-05-01T08:04:46.258450+00:00 app[web.1]: npm ERR! npm  v3.10.10
2017-05-01T08:04:46.258743+00:00 app[web.1]: npm ERR! moh@ start: `node server.js`
2017-05-01T08:04:46.258836+00:00 app[web.1]: npm ERR! Exit status 1
2017-05-01T08:04:46.258984+00:00 app[web.1]: npm ERR! 
2017-05-01T08:04:46.259080+00:00 app[web.1]: npm ERR! Failed at the moh@ start script 'node server.js'.
2017-05-01T08:04:46.259251+00:00 app[web.1]: npm ERR! If you do, this is most likely a problem with the moh package,
2017-05-01T08:04:46.259162+00:00 app[web.1]: npm ERR! Make sure you have the latest version of node.js and npm installed.
2017-05-01T08:04:46.259342+00:00 app[web.1]: npm ERR! not with npm itself.
2017-05-01T08:04:46.259435+00:00 app[web.1]: npm ERR! Tell the author that this fails on your system:
2017-05-01T08:04:46.259520+00:00 app[web.1]: npm ERR!     node server.js
2017-05-01T08:04:46.259593+00:00 app[web.1]: npm ERR! You can get information on how to open an issue for this project with:
2017-05-01T08:04:46.259672+00:00 app[web.1]: npm ERR!     npm bugs moh
2017-05-01T08:04:46.259762+00:00 app[web.1]: npm ERR! Or if that isn't available, you can get their info via:
2017-05-01T08:04:46.259842+00:00 app[web.1]: npm ERR!     npm owner ls moh
2017-05-01T08:04:46.259934+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2017-05-01T08:04:46.263264+00:00 app[web.1]: 
2017-05-01T08:04:46.263441+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2017-05-01T08:04:46.263496+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2017-05-01T08:04:46.321834+00:00 heroku[web.1]: Process exited with status 1
2017-05-01T08:04:46.332504+00:00 heroku[web.1]: State changed from starting to crashed

I tried to add the following in the package.json file

"scripts": {
        "start": "node server.js"
    }

but I end up with the same error,

here is my server.js code:

var express    = require('express');
var app        = express();
var bodyParser = require('body-parser');
var routes     = require('./routes');
var usersRoute = require('./usersDetailsRoutes');

var morgan = require('morgan');  

var mongoose = require("mongoose");
mongoose.connect('mongodb://behrouz:zxcv1234@ds017514.mlab.com:17514/sourceplaze');

require('./config/passport')(passport);


app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use(morgan('dev'));

app.use(passport.initialize());

var port = process.env.PORT || 8080;

app.use('/', routes);
app.use('/users', usersRoute)

app.listen(port);
console.log('listening on port: ' + port);

module.exports = app;

what am I doing wrong here?

Behrouz Riahi
  • 1,751
  • 2
  • 21
  • 42

3 Answers3

4

My guess is you deploy the content of your node-modules project folder with a bcrypt package that do not work on Heroku.

Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header

You should add the node-modules folder in your .gitignore and just deploy the package.json file on the server, as this answer suggests.

Community
  • 1
  • 1
TGrif
  • 5,725
  • 9
  • 31
  • 52
1

I know this is an old post but just found an option that worked for me

  1. npm uninstall bcrypt
  2. npm install bcryptjs

Replace bcrypt with bcryptjs everywhere it appears in your code, or just const bycrypt = require('bcryptjs') instead of const bcrypt = require('bcrypt')

adshay18
  • 11
  • 1
0
npm uninstall bcrypt

npm install bcryptjs

Replace bcrypt with bcryptjs everywhere it appears in your code, or just:

const bycrypt = require('bcryptjs')

Instead of:

const bcrypt = require('bcrypt')
Tyler2P
  • 2,324
  • 26
  • 22
  • 31