admin管理员组文章数量:1245084
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:
- I checked if the
crypto
module is available in my Node.js environment. - I attempted to set a fallback using
bcrypt.setRandomFallback(() => require("crypto").randomBytes(16));
, but the issue persisted.
Node.js version is v18.18.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:
- I checked if the
crypto
module is available in my Node.js environment. - I attempted to set a fallback using
bcrypt.setRandomFallback(() => require("crypto").randomBytes(16));
, but the issue persisted.
Node.js version is v18.18.0
Share Improve this question asked Feb 15 at 8:49 Nijat AliyevNijat Aliyev 89411 silver badges19 bronze badges1 Answer
Reset to default 1Solution:
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!
本文标签: nodejsNeither WebCryptoAPI nor a crypto module is available in bcryptjs v300Stack Overflow
版权声明:本文标题:node.js - Neither WebCryptoAPI nor a crypto module is available in bcryptjs v3.0.0 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740245780a2248212.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论