bcrypt invalid elf header when running node app
Solution 1:
I've found that bcrypt compiled on OSX will not quite work on Linux. In other words, if you check in the bcrypt compiled on your local OSX workstation, and try to run the node app on your linux servers, you will see the error above.
Solution: npm install bcrypt
on Linux, check that in, solved.
Probably the best way to deal with this is exclude your node_modules in .gitignore... and npm install remotely.
Solution 2:
If you are running inside a docker container as I am, all you need is a .dockerignore with 'node_modules' specified in it.
Some libraries need to be compiled on the host machine and therefore your modules can be stale.
Solution 3:
My issue was with my docker-compose.yml file, I already had node_modules in my .dockerignore but I also needed to add the node_modules directory as a volume:
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
Solution 4:
I was also facing the same issue with bcrypt v.1.0.3. Just updated to the latest version (3.0.1) and its working fine now
Run
npm install bcrypt@latest --save
Solution 5:
There is a simple way that allowed me to solve this problem:
1. Uninstall bcrypt
npm uninstall bcrypt
2.- Install bcrypt again
npm i bcrypt
The 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.
-------- UPDATE ----------------------------------------
It also seems to me that another solution which is to grant root permissions to bcrypt installation, it happens because bcryp uses its own user but it has no permissions, so:
1. You must grant root permission to your project folder. go outside of your project folder and then
sudo su
Then enter your root password to get root user permissions
2. Grant permission to your project folder
chmod -R 777 <project_folder>
3. Go to your project folder and install bcrypt
cd <project_folder>
AND
npm i bcrypt --unsafe-perm=true --allow-root --save
Ready, if everything was OK, your bcrypt module will install without problems.