Nijat Aliyev
Nijat Aliyev

Reputation: 894

Neither WebCryptoAPI nor a crypto module is available in bcryptjs v3.0.0

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

What I Tried:

Node.js version is v18.18.0

Upvotes: 0

Views: 174

Answers (1)

Nijat Aliyev
Nijat Aliyev

Reputation: 894

Solution:

I downgraded bcryptjs to version ^2.4.3, and the issue was resolved:

npm install [email protected]

Now, password hashing works without errors.

Question:

  • Why does bcryptjs v3.0.0 require WebCryptoAPI or an external crypto module, while v2.4.3 works fine?
  • Is there a proper way to make it work with v3.0.0 without downgrading?

Hope this helps others facing the same issue!

Upvotes: 1

Related Questions