node.bcrypt.js: Error: invalid ELF header
I am trying to deploy my REST API to heroku. Although, the application is working on my computer, it is not working on heroku. In the application log, i got this
Process exited with status 1
2019-09-23T01:09:55.744676+00:00 heroku[web.1]: Starting process with command `node server.js`
2019-09-23T01:09:58.446510+00:00 heroku[web.1]: Process exited with status 1
2019-09-23T01:09:58.468276+00:00 heroku[web.1]: State changed from starting to crashed
2019-09-23T01:09:58.370869+00:00 app[web.1]: internal/modules/cjs/loader.js:807
2019-09-23T01:09:58.370888+00:00 app[web.1]: return process.dlopen(module, path.toNamespacedPath(filename));
2019-09-23T01:09:58.370890+00:00 app[web.1]: ^
2019-09-23T01:09:58.370892+00:00 app[web.1]:
2019-09-23T01:09:58.370894+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2019-09-23T01:09:58.370896+00:00 app[web.1]: at Object.Module._extensions..node (internal/modules/cjs/loader.js:807:18)
2019-09-23T01:09:58.370898+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-09-23T01:09:58.370900+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-09-23T01:09:58.370902+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-09-23T01:09:58.370904+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-09-23T01:09:58.370906+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-09-23T01:09:58.370909+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2019-09-23T01:09:58.370910+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
2019-09-23T01:09:58.370912+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
2019-09-23T01:09:58.370915+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:653:32)
2019-09-23T01:09:58.370917+00:00 app[web.1]: at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
2019-09-23T01:09:58.370919+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:585:3)
2019-09-23T01:09:58.370921+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:692:17)
2019-09-23T01:09:58.370923+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:25:18)
2019-09-23T01:09:58.370924+00:00 app[web.1]: at Object.<anonymous> (/app/routes/auth.js:6:16)
2019-09-23T01:09:58.370926+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:778:30)
This seems to have something to do with bcrypt module. I tried the solutions suggested here: https://github.com/kelektiv/node.bcrypt.js/issues/595 and https://github.com/kelektiv/node.bcrypt.js/issues/635
such as: npm rebuild bcrypt --build-from-source
here is package.json file:
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^3.0.6",
"body-parser": "^1.18.3",
"cors": "^2.8.4",
"cron": "^1.7.2",
"express": "^4.16.3",
"jsonwebtoken": "^8.3.0",
"jwt-simple": "^0.5.6",
"mapnik": "^4.3.1",
"mkdirp": "^0.5.1",
"mongoose": "^5.7.1",
"multer": "^1.4.1",
"nodemailer": "^6.3.0",
"request": "^2.88.0",
"ug": "0.0.8"
}
}
I have node v10.16.3 and I am running MacOS v10.14.6
None of those solutions worked for me! Is the problem has to do with bcrypt or heroku? How can I solve this problem?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 16
Alternatively, you can use bcryptjs đ¤ˇ
For those using bcrypt with docker container:
Create
.dockerignorefile and add inside .dockerignore the following line:node_modulesNode modules will automatically be created upon npm install. This is done automatically by heroku.
To setup your gitignore, create a file called â.gitignoreâ and add ânode_modulesâ to it. Delete the directory as well if you are checking them into your repository
On Tue, 24 Sep, 2019, 5:00 am Abdulaziz, notifications@github.com wrote:
You are pushing compiled
bcryptbinaries to heroku (which is linux). Trying to load macOS binaries in Linux will give that error. Setup your gitignore properly to exclude node_modulesI think you can solve the problem by simply removing the
bcryptdependency from yourpackage.jsonfile (this file is in the root folder of your node project and you just need to delete the line"bcrypt": "version",), this prevents thenpm installcommand from installing thebcryptlibrary, so you just need to add the instruction to installbcrypt, adding the following line just after runningnpm installRUN npm i bcryptEnsure you are in the correct folder
There is a simple way that allowed me to solve this problem:
1. Uninstall bcrypt
npm uninstall bcrypt2.- Install bcrypt again
npm i bcryptThe error occurs because when you install bcypt, npm installs the recommended version for your machine and operating system, but when you are on another machine, this doesnât work
When I commented all the lines of code that has something to do with
bcryptthen deployed it again, it worked. This means the problem is definitely has something to do withbcrypt.I love you
I am still facing the issue with docker. could you please help me out. As i have already .dockerignore file and tried your method but doesât work for me. thanks
I just removed node_module directory from github then pushed modifications on heroku. That fixed my problem. Thanks to @agathver
@agathver
Setup your gitignore properly to exclude node_modulesignoring node_modules in gitignore would not have any effects on other dependencies? If not, how eactly can I set up my âgitignore properly to exclude node_modulesâ?