Skip to content
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: uuid not working when debugger is disabled #531

Closed
ghasemikasra39 opened this issue Nov 9, 2020 · 6 comments
Closed

React-native: uuid not working when debugger is disabled #531

ghasemikasra39 opened this issue Nov 9, 2020 · 6 comments

Comments

@ghasemikasra39
Copy link

Describe the bug

In my react-native application, I am using:

import { uuidv4 } from 'uuid';
uuidv4()

The uuid get generated successfully when the app is running on debug mode (The debugger is enabled). However, if you turn off the debugger, it does not work, as soon as the app reaches uuidv4() line of code, it stops there without any error in the console.

How to reproduce

  1. npx react-native init AwesomeProject
  2. yarn install uuid
import { uuidv4 } from 'uuid';
uuidv4()
  1. Test the app, should not work
  2. ctrl + d to open the developer menu, select Debug
  3. It will start working as normal

Expected behavior

The app should work as normal in both debug mode being enabled and disabled.

Runtime

System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 392.40 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
    Yarn: 1.22.4 - ~/Documents/youpendo-app-bareworkflow/node_modules/.bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.1, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.6 AI-192.7142.36.36.6392135
    Xcode: 12.1/12A7403 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_232 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: ^4.8.0 => 4.13.0
    react: 16.13.1 => 16.13.1
    react-native: 0.63.3 => 0.63.3

Additional information

[Any other information or comments that you think will help]

@ctavan
Copy link
Member

ctavan commented Nov 9, 2020

Did you follow the documentation and install react-native-get-random-values?

@broofa
Copy link
Member

broofa commented Nov 9, 2020

uuid doesn't export a uuidv4 property. Try import { v4 as uuidv4 } from 'uuid'; as suggested in documentation?

(@ctavan Am I missing something here? Is import {uuidv4} from 'uuid' expected to work with react-native and the react-native-get-random-values module somehow?)

@ctavan
Copy link
Member

ctavan commented Nov 9, 2020

Oops. I stopped reading the example code after import because I saw that the polyfill was missing… But you are obviously right, @broofa, in addition to the missing polyfill it must also read:

import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';

Just like in the documentation: https://github.com/uuidjs/uuid#react-native--expo

@ctavan
Copy link
Member

ctavan commented Nov 21, 2020

@ghasemikasra39 are you still experiencing this issue? If so please feel free to reopen this issue.

@ctavan ctavan closed this as completed Nov 21, 2020
@tunm1228
Copy link

tunm1228 commented May 4, 2021

you can downgrade to 3.3.3
=> yarn install [email protected]

@broofa
Copy link
Member

broofa commented May 4, 2021

@tunm1228 : That is not advisable. The reason that works is because pre-v7 versions of this library fall back to the [insecure / poor-quality] Math.random() RNG when crypto.getRandomValues() is not available. Just follow the instructions in the README as @ctavan suggests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants