node.bcrypt.js: [Solved] bcrypt fails at the install script at node-gyp rebuild

I get the folowing errors when trying to run npm install with "bcrypt": "^0.8.6" as a devDependency

error bcrypt@0.8.7 install: `node-gyp rebuild`
error Exit status 1
error Failed at the bcrypt@0.8.7 install script.
error This is most likely a problem with the bcrypt package,
error not with npm itself.
error Tell the author that this fails on your system:
error     node-gyp rebuild
error You can get their info via:
error     npm owner ls bcrypt
error There is likely additional logging output above.
error System Windows_NT 10.0.10586
error command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
error cwd C:\Users\username\Documents\my-app
error node -v v4.2.4
error npm -v 1.4.3
error code ELIFECYCLE
verbose exit [ 1, true ]

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 87

Commits related to this issue

Most upvoted comments

For anyone else struggling with this: http://stackoverflow.com/questions/29320201/error-installing-bcrypt-with-npm

I’m now using the bcrypt-nodejs library. npm install --save bcrypt-nodejs && npm uninstall --save bcrypt

I’ve been using it without any issues for a while now.

@conor909 you f**ing life saver man I almost died whole day trying to solve this shit. I love you so much ❤️.

@hofman-p This happens if your machine is incorrectly setup. We have comprehensive installation instructions https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions

Please read them before opening an issue, if it is an obvious case, the issue will be closed without any information, or a link at most depending on the maintainers’ mood

Thanks Conor

I had issue

https://forums.meteor.com/t/another-mup-failed-deployed-any/29277

and now this solved it for me:

$npm install --save bcrypt-nodejs && npm uninstall --save bcrypt

I have the same issue. Shame to to see it getting closed without a conversation. Thanks for the info @conor909.

My solution: 1)Go to visual studio code 2)Open package.json 3)Delete bcrypt dependency from package.json 4)Now open terminal and run npm install bcrypt 5)Restart visual studio code(Always a good practice if things not working 😃)

Still causes issues in 2018

You need to install with npm version 3: https://github.com/RocketChat/Rocket.Chat/issues/5210 npm install -g npm@3

Still causing this error in 2020 😕

This bcrypt module has been a pain for so many years, unbelievable!

install npm i node-pre-gyp after that use npm i bcrypt

For anyone else struggling with this: http://stackoverflow.com/questions/29320201/error-installing-bcrypt-with-npm

I’m now using the bcrypt-nodejs library. npm install --save bcrypt-nodejs && npm uninstall --save bcrypt

I’ve been using it without any issues for a while now.

if anyone still struggle with bcrypt on Amazon Linux, try bcryptjs. coz bcrypt-nodejs has deprecated now

npm install --save bcryptjs && npm uninstall --save bcrypt

replace your const bcrypt = require(‘bcrypt’) with const bcrypt = require(‘bcryptjs’) and everything will work fine : )

still causing this error in 2021

First uninstall bcrypt npm uninstall --save bcrypt then: npm install --save bcryptjs

see : link bcryptjs

please use this package to solve the problem https://www.npmjs.com/package/bcryptjs

I had the same error and verified that I was using node10, I changed via nvm to node9 and it worked

Horrible that this is an one year old issue and is still out there causing pain (Y)

Still causing this error in 2019.I just migrated to bcryptjs, worked 100% fine. link to the package: https://www.npmjs.com/package/bcryptjs

on mac os following solution worked for me Install Xcode Run sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

sources https://github.com/nodejs/node-gyp/issues/569

Spent 5 hours trying to get bcrypt to work. SO MUCH THANX HACKER!

The solution to this error is : First npm uninstall bcrypt or npm uninstall bcrypt-nodejs ( if bcrypt or bcrypt-nodejs exist in package.json Then npm install bcryptjs
I try to use bcrypt-nodejs but it only helps to push to heroku without error , but it will give error when hashing and genSalt , I think npm install bcryptjs is the best solution

Ubuntu 18.04

it worked for me -> sudo apt-get install build-essential

no other solution present here had worked.

It was a new machine (azure VM) and I had forgotten and installed this package.

If u are using nodejs then use sudo npm install --save bcryptjs.and restart the server.

The problem is, installing the bcrypt module re-launches the npm install command after you’ve explicitly did:

npm install

Note: For some packages. You’ll notice bcrypt has its own node_modules folder as a module itself.

To remedy the situation of node-gyp or node-pre-gyp being locked out of the equation, you first need to be sure to NOT do sudo as in:

sudo npm install

But the trick is, you do need sudo. Therefore you’ll have to go with this document https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally

Once that is done, you’ll be able to simply do npm install with the proper privileges, and rebuild successfully.

If you are using nvm, you’ll have to set the prefix as recommended here: https://stackoverflow.com/questions/34718528/nvm-is-not-compatible-with-the-npm-config-prefix-option

Changing to node 9 fixed the issue for me 👍

migrated to https://www.npmjs.com/package/bcryptjs and now everything is working

In node v14.16.0 I only tried:

<npm install --save bcrypt@5.0.0>. It worked.

*It used a request for node-pre-gyp https download.

SOLUTION: (worked for me)

Install C++ Compiler, make, and Python 2 (Well Linux has it already). https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions#fedora

It’s something to do with the way the snap package for npm’s confiment works, if you manually run it outside the sandbox, or with an fnm-provided version of node it works fine.

Fine:

/snap/node/7823/bin/node /snap/node/7823/bin/npm install bcrypt

Not fine:

/snap/bin/node  /snap/node/7823/bin/npm install bcrypt

I’m unable to e.g. strace through snap-confine and don’t care about it, so can’t guess what that error 7 really means, but I’m going to guess “snap sandbox kill”, despite sandboxing being off.

I had a similar issue in a project using bcrypt. It appears that it came from the bcrypt version in my package.json file. I solved it by reinstalling bcrypt. I would not recommend using bcrypt-nodejs as it is depreciated.

Best solution is to use the node version compatible with the bcrypt version

For anyone reading this thread, this, in combination of:

This happens if your machine is incorrectly setup. We have comprehensive installation instructions https://github.com/kelektiv/node.bcrypt.js/wiki/Installation-Instructions

Please read them before opening an issue, if it is an obvious case, the issue will be closed without any information, or a link at most depending on the maintainers’ mood

solved my problem. I’m currently using Node version 12.15 by the way. Upgraded bcrypt from 1.0.3 to 3.0.8. Everything works without any problems.

This is an issue with node-gyp, it doesn’t work with Python 3+.

sudo apt install python2.7    
ln -s /usr/bin/python2.7 /usr/bin/python

Install python 2.7 and set its executable as the default, then install again. If you need python3 later you can always replace the symbolic link.

Summary of what helped me for the following setup:

Ubuntu 23
Node 18.19.0
npm 10.2.3
bcrypt 5.1.1

For bcrypt to work, you need node-gyp as stated in the package docs.

npm install -g node-gyp

node-gyp itself requires other dependencies: make, gcc, and python. The first two you can get one-by-one or by installing build-essential:

sudo apt-get install build-essential

node-gyp works with python3, don’t let bcrypt’s wiki page that was referenced in this github issue a lot confuse you.

sudo apt-get install python3

And then as suggested by @dantaeusb, clean cache and, I would add, remove node modules, that last piece was crucial for my setup to finally start working:

rm -rf node_modules
npm cache clean --force
npm install

My solution: 1)Go to visual studio code 2)Open package.json 3)Delete bcrypt dependency from package.json 4)Now open terminal and run npm install bcrypt 5)Restart visual studio code(Always a good practice if things not working 😃)

Thank you sooo much. It worked on Mac - M1 👍 I firstly changed my node version to current stable version. Then I applied this method

"node-gyp only works with stable/released versions of node. Since the bcrypt module uses node-gyp to build and install, you’ll need a stable version of node to use bcrypt. "

I got this error while installing in docker and for me updating the version of bcrypt to 5.0.0 in package.json worked for me.

Ubuntu 18.04

it worked for me -> sudo apt-get install build-essential

no other solution present here had worked.

It was a new machine (azure VM) and I had forgotten and installed this package.

This works for me on Ubuntu 18.04 EC2 Instance. Thanks!

Best solution is to use the node version compatible with the bcrypt version