StableLib / stablelib

A stable library of useful TypeScript/JavaScript code
https://www.stablelib.com
Other
175 stars 36 forks source link

@stablelib/random unable to resolve module `crypto` in react native #14

Closed kenhuang closed 5 years ago

kenhuang commented 5 years ago

Reference @stablelib/random in RN app result unable to resolve module crypto error.

A possible fix is to add the following to package.json, this should allow RN env bypass crypto package.

  "react-native": {
    "crypto": false
  }
Screen Shot 2019-11-01 at 5 00 23 PM
dchest commented 5 years ago

What does it use instead of randomBytes in this case?

dchest commented 5 years ago

Last time I checked, RN didn't have any random number generator, is this correct? People used https://github.com/ReactWindows/react-native-randombytes or something else -- will setting "crypto": false make it still possible to use those (e.g. when people have babel replacements for it)?

kenhuang commented 5 years ago

We are using react-native-securerandom, https://github.com/rh389/react-native-securerandom

For our usage we don’t use the crypto related functions, fix above just try to avoid RN package manage blowout on start.

dchest commented 5 years ago

OK, got it. Merged and published.