Reputation: 894
I recently upgraded bcryptjs
to version ^3.0.0
in my Node.js project and encountered the following error while trying to hash a password:
const bcrypt = require("bcryptjs");
const password = "mypassword";
const hashedPassword = bcrypt.hashSync(password, 10);
console.log(hashedPassword);
Error:
Error: Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative
crypto
module is available in my Node.js environment.bcrypt.setRandomFallback(() => require("crypto").randomBytes(16));
, but the issue persisted.Node.js version is v18.18.0
Upvotes: 0
Views: 174
Reputation: 894
I downgraded bcryptjs
to version ^2.4.3
, and the issue was resolved:
npm install [email protected]
Now, password hashing works without errors.
bcryptjs
v3.0.0 require WebCryptoAPI or an external crypto module, while v2.4.3 works fine?Hope this helps others facing the same issue!
Upvotes: 1