-
-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Native: crypto.getRandomValues() is not available when debugging with Chrome #416
Comments
This only seems to be a problem when running in debug mode. In a release build it works. |
Seems to only affect debug builds in the iOS simulator. Running on device with debug or release build works fine. But debug mode on simulator throws the errors. Simulator is 11 Pro Max with iOS 13.4 |
Thanks for the report! @LinusU can you look into this? |
This issue exists also for Android React Native. The issue exists with or without debugging enabled. ~~This previously worked without any issue on Current version may need to polyfill crypto as mentioned in auth0/react-native-auth0#276 (comment) |
This sounds really strange. @joebernard @slapbox would you mind trying out https://github.com/ctavan/uuid-example-react-native (which "works on my machine™", at least for iOS) and see if you can find any differences to your code base? |
@ctavan the first thing that stands out, which I meant to mention, is that we're using the Expo version of React Native, so we can't easily set that up to test unfortunately. Maybe this is the issue with Expo, but that doesn't seem to explain the trouble @joebernard is having. |
Oh, if you are running expo then you will indeed run into the problem described here. The best thing you can do is to chime in over at expo/expo#7209 and express your support for adding this feature to expo. It's true that @joebernard's issue might be a different one (regarding debug mode) and we'll have to investigate further. |
I think I fixed it in my project. I upgraded React Native from |
Glad to hear! If there's further trouble please feel free to open a new issue. |
So I get this issue when trying to run via vscode debugger but not when running directly via the react-native cli. Update: stopping the debugger after running via vscode seems to remove the issue. IssueRuntime
vscode launch.json
Yarn cli
Both methods run in debug, as far as I know |
I thought that when running under Chrome there would already be a global |
Possibly this is an actual bug in react-native: facebook/react-native#26705 |
Ah no, I was reading that issue in a wrong way. We'll probably have to fix this in react-native-get-random-values in a similar way like here: facebook/react-native@4fd9c9d |
OK, I gave this a quick try and |
Hmm, if we guard it behind the double ifs as they do I guess that we could possibly fall back to an insecure implementation 🤔 if (__DEV__) {
if (isAsyncDebugging) {
// Hard code light theme when using the async debugger as
// sync calls aren't supported
return 'light';
}
} But yeah, it feels a bit dirty, any other solutions or ideas would be very welcome! |
Any update on this? A client app is near completion but I can't use the VS Code debugger nearly at all until this is solved. |
@alexanderblackh unfortunately I still have a hard time reproducing this issue since I'm not familiar with VS Code. Could you provide more detailed steps to reproduce so that I can try to further investigate the issue? Ideally using https://github.com/ctavan/uuid-example-react-native as a reproduction repo. Thanks! |
@alexanderblackh As a temporary solution that helped me, you can do this. declare var global: any;
if (__DEV__ && typeof global.crypto !== 'object') {
global.crypto = {
getRandomValues: (array: any[]) => array.map(() => Math.floor(Math.random() * 256)),
};
} else {
require('react-native-get-random-values');
} |
@alexanderblackh @seralexeev what version of It looks like the workaround proposed by @seralexeev should already be part of react-native-get-random-values@1.4.0. Could you try it with the latest version of |
@seralexeev @ctavan Sorry for delay in response. Tried both of those solutions in the RN app, not only is it not working, but it seems this isn't working in the Release build period, any page using it crashes outright (it does work in a debug build however, just not with the VSCode debugger attached). Import and censored usage is as follows:
Using uuidjs 7.0.3 and get-random-values 1.40 |
@alexanderblackh did you try the manual workaround described here: #416 (comment) ? Something like: if (__DEV__ && typeof global.crypto !== 'object') {
global.crypto = {
getRandomValues: (array: any[]) => array.map(() => Math.floor(Math.random() * 256)),
};
} |
Are there any news about this issue? |
No news, but I also don't know how to reproduce this issue. If anyone can provide a reproduction case and exact steps to reproduce I'm happy to have a look. |
I’ve updated my project to the last react and react-native version and everything works fine now. |
@ctavan I've tried now the following steps to test and got the error: Creates a new fresh app and install
In App.tsx i printed some import { v4 as uuidv4 } from 'uuid'
// in App component
<Text>{uuidv4()}</Text> Running the app on Android device: My dependencies:
Thanks! |
@edolix you need a polyfill, did you follow https://github.com/uuidjs/uuid#react-native ? @osvald0 great to hear! @joebernard does upgrading to latest |
@ctavan Unfortunately I still have this issue.
|
That's sad to hear. Could you give me the exact steps to reproduce to activate debug mode, @joebernard? I'm not a react-native pro, sorry! |
@joebernard do you get the error with and without debugging mode on? React Native is weird as hell sometimes with stuff like that, so asking for completeness' sake since at least one person now has it working. Also, what OS? |
Also, don't forget to link |
I hope the Expo team is planning to link |
Good callout! cc @brentvatne |
Unfortunately no progress so far, but feel free to give your 👍 to expo/expo#7209 @amhinson @slapbox @benjreinhart |
Sorry for the disappearing act. Can't speak about Expo, but in vanilla React Native, I got it working again after making various other changes and then it just started working fully, including in release builds. If you get this error, I'm pretty sure it's a result of something else breaking and it causing havoc throughout the app, but I can't confirm. If I get it again, I'll report back with vastly more details. |
I got this error today and I could only get it working by manually running |
@ortonomy I believe this is something that would rather belong to https://github.com/LinusU/react-native-get-random-values since the |
@ctavan -- for sure, I'd be happy to do it. It's starting to become an annoyance. |
I was facing the same issue in my project because of using realm. |
@kiran-kumar011 how did you solve it? Same issue with RealmJS: realm/realm-js#3714 |
React Native
|
What I did :
then
then
|
I followed the steps in the Readme and it worked. I believe from uuid version 3.3 to 7+ version you need react-native-get-random-values library |
Ok, what you should do is:
|
For those using expo: expo has its own library called |
@qoobes thanks for sharing! Quick question: We've been using the |
@Nantris So expo-crypto is a sort of port of the standard node crypto library, meaning that it should be the exact same since |
Describe the bug
My React Native project has been using uuid for a while with no problem. I upgraded to v7 and installed
react-native-get-random-values
. I addedimport 'react-native-get-random-values';
and changed my uuid import toimport {v4 as uuidv4} from 'uuid';
I cleaned the build in Xcode, deleted derived data, cleared watchman and metro cache, reinstalled all node modules, and ran pod install.I still get this error:
I also tried moving the
react-native-get-random-values
import to my index.js per this comment but then got this error:To Reproduce
I followed instructions in the readme.
Expected behavior
Generate uuid.
Runtime
React Native
The text was updated successfully, but these errors were encountered: