setRandomFallback doesn't work in environments that support commonJS but are not Node.js
I am working on a React Native project to build a mobile app. React Native essentially runs on JavaScriptCore for iOS and Android devices which is the JS engine that powers Safari (https://facebook.github.io/react-native/docs/javascript-environment.html).
The problem is, this environment does support commonJS style requires & exports, but since it doesn't run on Node.js environment, it doesn't have Node's core modules like crypto. This causes the setRandomFallback to not work even if I set it and throw a module not found error for crypto. This is because the way fallback is defined within random function, the first check looks for this: (typeof module !== 'undefined' && module && module['exports'])
I'm not sure if you'd like me to add React Native specific check because this is a generic library, but I think we should do this check in a way that supports such environments.
I am also unable to import this package. So I am requiring the copy named react-native-bcrypt. Any help on how to import it, by the way?
@jsdario I actually forked this repo and created aforementioned react-native-bcrypt package myself a while ago. The only way for now seems to use that package or change the randomFallback check to fit your usage. My fork is here: https://github.com/emiraydin/react-native-bcrypt
Hi @emiraydin! Thank you for your fork, it helped a lot. Although, I had to spend hours figuring out why this won't work for release builds on both Android and iOS.
Uint8Array.prototype.map is not defined on Android. We can either not use map or add something like below in your libaray.
if (!Uint8Array.prototype.map) {
Uint8Array.prototype.map = Array.prototype.map;
}
This works fine on iOS unless you're using btoa in which case something like below would work.
if (!global.btoa) {
global.btoa = require('base-64').encode;
}