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

null is not an object (evaluating RNRandomBytes.seed) #40

Open
JUDOKICK opened this issue Feb 10, 2020 · 16 comments
Open

null is not an object (evaluating RNRandomBytes.seed) #40

JUDOKICK opened this issue Feb 10, 2020 · 16 comments

Comments

@JUDOKICK
Copy link

I am currently unable to use react-native-crypto because randombytes throws this null error.
I am using an ejected Expo, SDK35, and all steps followed from react-native-crypto
I have linked correctly, used rn-nodeify and imported the shim file and still it is not working.

I have tried possibly all combinations of steps and procedures for installations and none of them seem to work for the latest expo/react-native sdks.

It has to do with this section of code

let sjcl = require('sjcl')
`let RNRandomBytes = require('react-native').NativeModules.RNRandomBytes

function noop () {}

function toBuffer (nativeStr) {
return new Buffer(nativeStr, 'base64')
}

function init () {
if (RNRandomBytes.seed) {
let seedBuffer = toBuffer(RNRandomBytes.seed)
addEntropy(seedBuffer)
} else {
seedSJCL()
}
}The error is line 15 if (RNRandomBytes.seed)` meaning that it never gets initialized somehow

@LuisAcerv
Copy link

Did you found a solution for this?

@JUDOKICK
Copy link
Author

No unfortunately. I ended up just using the native crypto libraries in Android to get it to work. Very frustrating issue though.

@Yasir-Shah
Copy link

Yasir-Shah commented May 1, 2020

@JUDOKICK I'm having the same issue, please help is there any workaround?
I spent 5days on it but that issue is still there how can I fix this problem?
What did you in your case? how did you implement a native crypto library in android?

@JUDOKICK
Copy link
Author

JUDOKICK commented May 1, 2020

Using Java and linking the two with an ejected version of my app. There is no fix for this. React-Native won't support new NodeJs libraries. This used to work on older versions. But now all the libraries that end up needing the NodeJs libraries use newer versions. Unless you feel like digging through your dependencies and locking each specific version just to get this to work. I highly suggest ejecting and using the native java/swift libraries.

@Yasir-Shah
Copy link

Yasir-Shah commented May 1, 2020

ok, thanks may I know how can I use native libraries? Can you share a code example like you did it would be really helpful for me?
Please help

@JUDOKICK
Copy link
Author

JUDOKICK commented May 1, 2020 via email

@starpl
Copy link

starpl commented Mar 23, 2021

I found a temporary solution to this problem
well maybe not temporary but its kind of hack

To add missing native module you need to manually add specific files from this repo to your project

For example, if you need this to work on Android, you have to copy two files in android/src/main/java/com/bitgo/randombytes/
You need to use those two files like if you wanted to implement your own native modules; you can find guide how to connect everything right here

And after that, in debug mode I was able to see that native module is not null and everything works fine

@jxiu0129
Copy link

In my case, I had react-native-randombytes installed. Maybe you did the react-native link or react-native link react-native-randombytes as me. I opened podfile and it did link for us. However, if you opened pod.lock and looked for it, it did not auto install for us. I went to ios folder and pod install, it finally works. this issue wasted me like 5 days.

@ebma
Copy link

ebma commented Sep 30, 2021

I think expo is the problem here. I tried setting it up with this boilerplate where you can specify if you want to use expo for your project or not. Without expo it is working fine and with expo it fails with this error.

Just wanted to leave this comment in case it helps anyone pin down the issue.

@adamsr123
Copy link

adamsr123 commented Feb 26, 2022

This was a problem for me while working with expo SDK and I needed rn-nodeify:

  1. Run postinstall rn-nodeify.
  2. Removed the postinstall and react-native-randombytes
  3. expo install react-native-randombytes

I think that by running the 3rd command with expo and not with rn-nodeify it linked the needed dependencies.

Update: It created another problem, so didn't fix it. I think metro config fixed the problem.

@EL-MehdiLoukach
Copy link

I have an expo application, I added the import statement to my code and suddenly faced this error ? is there anyway to make it work with expo ?

@alexanderbkl
Copy link

alexanderbkl commented Jul 27, 2022

I fixed it by opening the file explorer and explicitly searched for all the files inside my project that contain "RNRandomBytes.seed" text in them and then, inside all of the file indexes found, I just replace the init() function with this code:

function init () {
  if (RNRandomBytes) {
    if (RNRandomBytes.seed) {
      let seedBuffer = toBuffer(RNRandomBytes.seed)
      addEntropy(seedBuffer)
    } else {
      seedSJCL()
    }
  }
}

@mohammadsadeghforoughi
Copy link

I still have this issue with expo

@StuartFlutter
Copy link

3. expo install react-native-randombytes

Can you elaborate on exactly how this fixed your issue please? I have the same error and tried this hacky approach only to have the app fail in a similar fashion - "o.default.randomBytes is not a function"

@StuartFlutter
Copy link

3. expo install react-native-randombytes

Does your app not need RNRandomBytes? Do you do any crypto operations in your app?

I am struggling to get this fixed.

@andresmejia3
Copy link

In my case, I had react-native-randombytes installed. Maybe you did the react-native link or react-native link react-native-randombytes as me. I opened podfile and it did link for us. However, if you opened pod.lock and looked for it, it did not auto install for us. I went to ios folder and pod install, it finally works. this issue wasted me like 5 days.

You are a god among men

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