You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to use genSalt function on es modules I get the following error: Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative. It works on commonjs.
I took a look into the bcryptjs source code and I found this:
function random(len) {
/* node */ if (typeof module !== 'undefined' && module && module['exports'])
try {
return require("crypto")['randomBytes'](len);
} catch (e) {}
/* WCA */ try {
var a; (self['crypto']||self['msCrypto'])['getRandomValues'](a = new Uint32Array(len));
return Array.prototype.slice.call(a);
} catch (e) {}
/* fallback */ if (!randomFallback)
throw Error("Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative");
return randomFallback(len);
}
I believe the problem is that module['exports'] parameter, which, of course, doesn't exists in esm nodejs. I think a better verification method is to check if process object exists. Please take a look on this issue, thanks!
The text was updated successfully, but these errors were encountered:
When I try to use genSalt function on es modules I get the following error:
Neither WebCryptoAPI nor a crypto module is available. Use bcrypt.setRandomFallback to set an alternative
. It works on commonjs.I took a look into the bcryptjs source code and I found this:
I believe the problem is that
module['exports']
parameter, which, of course, doesn't exists in esm nodejs. I think a better verification method is to check ifprocess
object exists. Please take a look on this issue, thanks!The text was updated successfully, but these errors were encountered: