Cannot find module 'bcrypt'
node.jsnode.js Problem Overview
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)
node.js Solutions
Solution 1 - node.js
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
Solution 2 - node.js
The solution for me was to npm rebuild
.
Solution 3 - node.js
use bcryptjs instead bcrypt this is worked for me
npm install bcryptjs --save
Solution 4 - node.js
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
Solution 5 - node.js
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.
Solution 6 - node.js
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
Solution 7 - node.js
Before using npm install
, change the package.json
file dependencies, i.e.
"bcrypt":"0.7.6"
to
"bcrypt":"*"
Solution 8 - node.js
This worked for me.
-
Delete any
bcrypt
folder innodemodules
folder, folder may have been created due to your repeated tries. (C:\Program Files\nodejs\node_modules\npm\node_modules
) -
run this code
npm install --save bcryptjs
e.g -C:\Projects\loginapp>npm install --save bcryptjs
Solution 9 - node.js
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
.
Solution 10 - node.js
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
Solution 11 - node.js
I'm using bcrypt
with typescript
npm i --save @types/bcryptjs
Helped me solve the error above.
Solution 12 - node.js
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>
Solution 13 - node.js
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
Solution 14 - node.js
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
Solution 15 - node.js
> I'm running Ubuntu 16.04 on DigitalOcean (512 MB / 1 CPU, 20 > GB SSD)
The following worked for me:
-
Scale your droplet up to the 1 GB RAM option ($10/mo)
-
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++
-
Then try again with:
npm install bcrypt --save
-
Scale droplet back down to the 512 MB option
Solution 16 - node.js
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!
Solution 17 - node.js
- 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.
Solution 18 - node.js
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.
Solution 19 - node.js
For me the issue resolved by below steps: Nothing above solved my issue,
- rm -rf node_modules in your project directory
- rm package-lock.json
- just check you have your package.json file now
- npm install
Thats it, you will get bcrypt installed properly. Hope this helps.
Solution 20 - node.js
This worked for me:
npm install bcryptjs
Then:
npm update
Solution 21 - node.js
First delete bcrypt module from your node modules. Then try the below steps:
-
npm install node-gyp -g
-
npm install bcrypt -g
-
npm install bcrypt -save
This will definitely resolve the issue.
Solution 22 - node.js
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.
Solution 23 - node.js
If this is an error you are facing when using something like Travis CI, consider using npm install --build-from-source
.
Solution 24 - node.js
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
Solution 25 - node.js
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]
Solution 26 - node.js
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
Solution 27 - node.js
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
Hope this helps.
Solution 28 - node.js
You have to install bcryptjs. Use npm install bcryptjs --save It worked for me when I was stuck here.
Solution 29 - node.js
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
Solution 30 - node.js
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
Solution 31 - node.js
For me, it was because bcryptjs
has a different name.
To fix it simply,
cd node_modules
Go to node_modules folder on your applicationln -s bcryptjs bcrypt
OR for Windowsmklink /D bcryptjs bcrypt
This creates a link of bcryptjs
directory to bcrypt
.
Solution 32 - node.js
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.
Solution 33 - node.js
What worked for me:
- Deleted node_modules
- Delete package-lock.json
- Reinstalled all the dependencies
Solution 34 - node.js
If above solutions don't work just delete Node modules
and package.json
then npm install --save
and then npm install bcrypt --save
Solution 35 - node.js
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');