node.jscryptographybcryptpassword-hashbcryptjs

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


Solution

  • Solution:

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

    npm install bcryptjs@2.4.3
    

    Now, password hashing works without errors.

    Question:

    Hope this helps others facing the same issue!