66

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)
Ramesh Chand
  • 1,750
  • 1
  • 10
  • 19

35 Answers35

73

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
tscpp
  • 903
  • 10
  • 27
Ramesh Chand
  • 1,750
  • 1
  • 10
  • 19
70

The solution for me was to npm rebuild.

Tyler Collier
  • 10,791
  • 9
  • 67
  • 79
18

use bcryptjs instead bcrypt this is worked for me

npm install bcryptjs --save
18

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

Eugène Beliaev
  • 861
  • 8
  • 4
13

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.

leompeters
  • 696
  • 11
  • 23
10

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

Abhu
  • 101
  • 1
  • 3
7

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

"bcrypt":"0.7.6" 

to

"bcrypt":"*"
piet.t
  • 11,400
  • 21
  • 42
  • 50
Krishna Mohan
  • 159
  • 1
  • 11
6

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 
Xpleria
  • 4,994
  • 5
  • 50
  • 60
Dholu
  • 539
  • 6
  • 11
4

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.

Dinesh
  • 364
  • 2
  • 12
thepanuto
  • 784
  • 4
  • 16
3

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 bcrypt@2.0.0 --save
Andreas Bigger
  • 4,728
  • 1
  • 11
  • 18
2

I'm using bcrypt with typescript

npm i --save @types/bcryptjs

Helped me solve the error above.

Black Mamba
  • 11,092
  • 6
  • 67
  • 93
2

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>
  • I had trouble with node 12. I downgraded to node 10 and removed the `node_modules` folder. After reinstalling, it worked! – joeytwiddle May 10 '19 at 02:38
  • 1
    @joeytwiddle If even that won't work, the best solution is to install `bcryptjs`. It has zero dependencies and it's not influenced by OS used.But first it needs to be uninstalled `bcrypt`. – Radisav Savkovic May 11 '19 at 12:30
  • I was trying to run this https://github.com/komarserjio/notejam The express version over node 12. I've tried this solution downgrading to node v10 and it worked! thanks. – Marlon Dias Nov 07 '19 at 21:40
  • One more tip would be to use bcryptjs instead of bcrypt. Bcrypt has a problem with dependencies very often – Radisav Savkovic Nov 07 '19 at 21:45
2

This happened to me as I was installing a package from github that had an older version of bcrypt as a dependency.

Just uninstall bcrypt to clear out the old version and install a new version:

npm uninstall bcrypt
npm install bcrypt
David S
  • 196
  • 3
  • 6
1

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

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

spencer.sm
  • 17,134
  • 10
  • 72
  • 83
1

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!

JoeTidee
  • 21,928
  • 22
  • 94
  • 135
Dijana
  • 11
  • 1
1
  • 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 bcrypt@3.0.6."

I hope it will resolve the issue.

0

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.

Kyaw Min
  • 23
  • 1
  • 10
0

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

This worked for me:

npm install bcryptjs

Then:

npm update
RileyManda
  • 2,376
  • 22
  • 30
0

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.

codeepic
  • 3,220
  • 6
  • 32
  • 56
Manasi Roy
  • 11
  • 2
0

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

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

Dev Yego
  • 486
  • 2
  • 11
0

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
Watercayman
  • 7,620
  • 10
  • 32
  • 46
0

I was using bcrypt@3.0.6 and @types/bcrypt@3.0.0 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 bcrypt@3.0.8

JaymesKat
  • 11
  • 3
0

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

Mr Coder
  • 467
  • 3
  • 13
0

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.

Murat Yıldız
  • 10,459
  • 6
  • 58
  • 60
0

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

  • bcryptjs is more simple to use than bcrypt because it is written purely in javascript, but beware it will be slower than the c++ version – Félix Brunet Jun 10 '20 at 21:00
0

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 bcrypt@5.0.0

and the error fixed.

Version Compatibility

Hamayun
  • 19
  • 1
0

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
tripleee
  • 158,107
  • 27
  • 234
  • 292
0

For me, it was because bcryptjs has a different name.

To fix it simply,

  • cd node_modules Go to node_modules folder on your application
  • ln -s bcryptjs bcrypt OR for Windows mklink /D bcryptjs bcrypt

This creates a link of bcryptjs directory to bcrypt.

True Kapo
  • 11
  • 3
0

In my case, after running the install commands and the commands suggested by others, my package.json file was not being updated. I manually included this dependency in my package.json file like below:

"dependencies": {
    ...
    "bcrypt": "5.0.1"
    ...
}

And then saved the file and ran npm install --save -g, this installed the missing packages.

Jamshaid K.
  • 2,427
  • 1
  • 20
  • 35
0

What worked for me:

  • Deleted node_modules
  • Delete package-lock.json
  • Reinstalled all the dependencies
Astrit Spanca
  • 424
  • 3
  • 12
0

If above solutions don't work just delete Node modules and package.json then npm install --save and then npm install bcrypt --save

0

if your issue didn't resolved. The below syntax will surely provide you a solution. To use bcrypt: var bcrypt = require('bcrypt'); To use bcryptjs. var bcrypt = require('bcryptjs');

Bipincr
  • 1
  • 1