Ramesh Chand
Ramesh Chand

Reputation: 2220

Cannot find module 'bcrypt'

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)

Upvotes: 90

Views: 185555

Answers (30)

Samopz
Samopz

Reputation: 1

When npm i bcrypt -g didn't work for me, then I run npm i bcrypt -d and that did work.

Upvotes: 0

Parris Varney
Parris Varney

Reputation: 11478

If you're using yarn, try installing with npm then just deleting the lock file after.

It seems it's an issue specific to yarn

See https://github.com/kelektiv/node.bcrypt.js/issues/1023

npm install bcrypt
yarn
rm package-lock.json

Upvotes: 0

Murat Yıldız
Murat Yıldız

Reputation: 12032

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

Upvotes: 0

David S
David S

Reputation: 442

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

Upvotes: 8

Bipincr
Bipincr

Reputation: 11

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');

Upvotes: 1

swado tech
swado tech

Reputation: 1

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

Upvotes: 0

Astrit Spanca
Astrit Spanca

Reputation: 724

What worked for me:

  • Deleted node_modules
  • Delete package-lock.json
  • Reinstalled all the dependencies

Upvotes: 0

Jamshaid K.
Jamshaid K.

Reputation: 4567

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.

Upvotes: 0

Nick Malon
Nick Malon

Reputation: 41

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.

Upvotes: 1

kiarash shamaii
kiarash shamaii

Reputation: 26

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

Upvotes: 0

Sahil Puri
Sahil Puri

Reputation: 1

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

Upvotes: 0

Hamayun
Hamayun

Reputation: 29

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

Upvotes: 0

Eug&#232;ne Beliaev
Eug&#232;ne Beliaev

Reputation: 1111

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

Upvotes: 25

Mr Coder
Mr Coder

Reputation: 523

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

Upvotes: 0

Ramesh Chand
Ramesh Chand

Reputation: 2220

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

Upvotes: 95

JaymesKat
JaymesKat

Reputation: 11

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]

Upvotes: 0

Hern&#225;n Pereyra
Hern&#225;n Pereyra

Reputation: 1

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

Upvotes: 0

Uthandi Karthi
Uthandi Karthi

Reputation: 11

  • 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.

Upvotes: 1

Dev Yego
Dev Yego

Reputation: 553

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

Upvotes: 0

Carl Gentleman
Carl Gentleman

Reputation: 39

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.

Upvotes: 0

Radisav Savkovic
Radisav Savkovic

Reputation: 23

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>

Upvotes: 2

Dijana
Dijana

Reputation: 11

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!

Upvotes: 1

Black Mamba
Black Mamba

Reputation: 15555

I'm using bcrypt with typescript

npm i --save @types/bcryptjs

Helped me solve the error above.

Upvotes: 3

Manasi Roy
Manasi Roy

Reputation: 11

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.

Upvotes: 0

RileyManda
RileyManda

Reputation: 2641

This worked for me:

npm install bcryptjs

Then:

npm update

Upvotes: 0

Andreas Bigger
Andreas Bigger

Reputation: 5550

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

Upvotes: 3

Mohamed Amine MAAROUFI
Mohamed Amine MAAROUFI

Reputation: 401

use bcryptjs instead bcrypt this is worked for me

npm install bcryptjs --save

Upvotes: 28

Abhu
Abhu

Reputation: 101

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

Upvotes: 10

user3399182
user3399182

Reputation: 1

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.

Upvotes: 0

Dholu
Dholu

Reputation: 697

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 

Upvotes: 6

Related Questions