62
votes

I am getting error Cannot find module 'bcrypt' in nodejs application

I have tried to install it using npm install bcrypt but still getting the issue.

node app.js

Error message:

Dec 30 2015 5:22:18 PM+05:30 - info: Connected to database:  
postgres://testdb:see2@$W@localhost/testdb

Dec 30 2015 5:22:18 PM+05:30 - error: Error: Cannot find module 'bcrypt'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (D:\...\server\modules\user\model
s\user.js:11:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
30
please provide the node.js code snippet - Shrikant
also, make sure you have bcrypt folder under APP_DIR/node_modules - prasun
Just checked in the node_module folder bcrypt not available there, how it's being disappear - Ramesh Chand
if bcrypt folder isn't there it is evident that the installation did don't went good - prasun
I am installing bcrypt module with npm install bcrypt command - Ramesh Chand

30 Answers

67
votes

Using npm install bcrypt command can't resolve the issue for me.

I tried the commands below and my issue resolved.

npm install node-gyp -g
npm install bcrypt -g

npm install bcrypt --save
64
votes

The solution for me was to npm rebuild.

17
votes

use bcryptjs instead bcrypt this is worked for me

npm install bcryptjs --save
16
votes

The Solution is pretty basic, I've solved this Error / Bug with the following steps:

Step 1: Uninstall the bcrypt package with this command :

npm uninstall bcrypt

Step 2: Then ReInstall it :

npm install bcrypt

13
votes

It should be npm install bcrypt --save. Works for me!

And, if you have others issues after install it, you can check your packages with npm-check.

10
votes

Solution 1: lengthy method is : Install all dependencies first.

npm install -g windows-build-tools, npm install -g node-gyp

then, install bcrypt : npm install bcrypt

Solution 2: easy method. No dependencies installation required.

npm install bcryptjs

...You might have installed bcrypt but it seems like the installation was not successful for some reason. check the package.json file. If you cannot find bcrypt, the installtion was unsuccessful. You have to install again.

As everyone explained, it because of lack dependencies that your installation was unsuccessful. You can checkout the required dependencies in the link: https://www.npmjs.com/package/bcrypt

Note: To use bcrypt: var bcrypt = require('bcrypt'); .....

to use bcryptjs. var bcrypt = require('bcryptjs');

for reference: https://www.npmjs.com/package/bcrypt https://www.npmjs.com/package/bcryptjs

7
votes

Before using npm install, change the package.json file dependencies, i.e.

"bcrypt":"0.7.6" 

to

"bcrypt":"*"
6
votes

This worked for me.

1) Delete any bcrypt folder in nodemodules folder, folder may have been created due to your repeated tries. (C:\Program Files\nodejs\node_modules\npm\node_modules)

2) run this code npm install --save bcryptjs e.g -

C:\Projects\loginapp>npm install --save bcryptjs 
4
votes

In my case, npm rebuild alone didn't solved it. I also had to:

$ npm install -g node-gyp
$ sudo apt-get update
$ sudo apt-get install build-essential
$ npm rebuild

npm rebuild was trying to run make.

3
votes

It seems that bcrypt was depreciated at version 1.0.3 as it was susceptible to a wrap-around bug. NPM recommends installing version 2.0.0.

So, if you wish to save it, just run the command:

npm install [email protected] --save
2
votes

If none of these examples didn't work, you should try to downgrade Node version installed:

E.g from Node version 10 to version 9

npm install node@<version of node>
1
votes

I'm running Ubuntu 16.04 on DigitalOcean (512 MB / 1 CPU, 20 GB SSD)

The following worked for me:

  1. Scale your droplet up to the 1 GB RAM option ($10/mo)

  2. Run each of the following commands (one at a time)

    sudo npm install node-gyp -g
    sudo apt-get install python
    sudo apt-get install make
    sudo apt-get install g++
    
  3. Then try again with:

    npm install bcrypt --save
    
  4. Scale droplet back down to the 512 MB option

1
votes

You need to update the g++ compiler version in your linux system. To update the compiler just run the commands below:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get install gcc-4.9 g++-4.9

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9


npm install bcrypt --save
1
votes

I'm using bcrypt with typescript

npm i --save @types/bcryptjs

Helped me solve the error above.

1
votes
  • Node Version vs Bcrypt Version
  • 0.4 <= 0.4
  • 0.6, 0.8, 0.10 >= 0.5
  • 0.11 >= 0.8
  • 4 <= 2.1.0
  • 8 >= 1.0.3
  • 10, 11 >= 3
  • 12 >= 3.0.6

I had the same issue, after I installed the bcrypt particular version depends on your node version, it started to working.

In my case my nodeJS version was 12.3.0 , so I installed by specifying the version " npm install [email protected]."

I hope it will resolve the issue.

1
votes

You have to uninstall bcrypt first since npm already installed some of it.

This happened to me as I was installing a package from github that had an older version of bcrypt as a dependency. I just uninstalled the old bcrypt version and installed the newest version:

npm uninstall bcrypt
npm install bcrypt

Then, voila. It worked.

0
votes

I can't run any npm commads. so, I download from this link https://github.com/kelektiv/node.bcrypt.js create folder bcrype and use it. Solve now.

0
votes

For me the issue resolved by below steps: Nothing above solved my issue, 1) rm -rf node_modules in your project directory 2) rm package-lock.json 3) just check you have your package.json file now 4) npm install

Thats it, you will get bcrypt installed properly. Hope this helps.

0
votes

This worked for me:

npm install bcryptjs

Then:

npm update
0
votes

First delete bcrypt module from your node modules. Then try the below steps:

1) npm install node-gyp -g

2) npm install bcrypt -g

3) npm install bcrypt -save

This will definitely resolve the issue.

0
votes

I followed some course, and for me it didn't work. My mistake was:

var bcrypt = require('bcrypt.js'); 

But when I changed it to

var bcrypt = require('bcryptjs');

It worked!

0
votes

Be sure you are in a stable version of node too. If you are working with n, you only need to:

sudo n stable

And then again:

npm install bcrypt --save

And it worked for me.

0
votes

If this is an error you are facing when using something like Travis CI, consider using npm install --build-from-source.

0
votes

The problem could be because there is no this essential

sudo apt-get install -y build-essential python

Then agregate bcrypt with if you're using npm:

npm install bcrypt
npm rebuild

or if you're using yarn:

yarn add bcrypt
yarn install
yarn build
0
votes

I was using [email protected] and @types/[email protected] with node 13.7.0 environment. I was running into error cannot find binding .../node_modules/../bindings/bcrypt_lib.node

I ran this to resolve issue:

  • npm i -g node-gyp
  • npm i bcrypt --save

This upgraded to [email protected]

0
votes

Using npm install bcrypt command can't resolve the issue for me.

finally, i fixed commands below and my issue resolved.

npm install node-gyp -g
# bcrypt reqired node-pre-gyp
npm install -g node-pre-gyp
npm install bcrypt -g

npm install bcrypt --save

node -v v8.16.1

npm -v 6.4.1

0
votes

If the problem could not solved after applying the workarounds above, you may try to update version in package.json as mentioned on [Fix bug] update bcrypt to 3.0.7

enter image description here

Hope this helps.

0
votes

Check your node version and then go to this link https://github.com/kelektiv/node.bcrypt.js to match compatible bcrypt version with your node.js version

I am using node.js v14.7.0 and when I tried to run 'npm install bcrypt or bcryptjs' it gives me errors then I run npm install [email protected]

and the error fixed.

Version Compatibility

0
votes

You have to install bcryptjs. Use npm install bcryptjs --save It worked for me when I was stuck here.

0
votes

First check node-modules folder for a folder with this name bcrypt. If it exists with another name just rename it; for example bcrypt-pbkdf must be edited to bcrypt. If there isn't such a folder, do this in cmd:

npm install node-gyp -g
# bcrypt reqired node-pre-gyp
npm install -g node-pre-gyp
npm install bcrypt -g
npm install bcrypt --save