rn-nodeify: undefined is not an object (evaluating 'RNRandomBytes.seed')

  • npm install rn-nodeify -g
  • npm install braintree --save
  • rn-nodeify --install “http,events,url,stream,buffer,https,crypto,vm” --hack
  • clone react-native node in package.json as braintree

Getting undefined is not an object (evaluating 'RNRandomBytes.seed') error in the var braintree = require("braintree");

Seems that it is failing somewhere in crypto. Any clues what the error may be and how to resolve it?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 33 (9 by maintainers)

Most upvoted comments

@mvayngrib I am facing the same issue when I uncomment require('crypto'); in the shim.js, I followed all the steps here and I tried to use rnpm link react-native-randombytes but it didn’t work as it supposed to be

Screenshot 2021-04-06 at 14 42 10

Any clues what the error maybe how to resolve it?

For iOS running “pod install” from ios directory helped for me

Any solution for iOS?

Typing the previous I had an idea and found a fix for the people interested. Following instructions from https://github.com/rebeccahughes/react-native-device-info I found you need some extra stops after linking react-native-randombytes

For Anroid (React Native: 0.29+)

  • react-native link react-native-randombytes
  • Register Module in MainApplication.java
import com.bitgo.randombytes.RandomBytesPackage;  // <--- import

public class MainApplication extends Application implements ReactApplication {
  ...
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new RandomBytesPackage, // <---- add this line here
          new MainReactPackage()
      );
    }
  ...
}

@mvayngrib I am facing the same issue when I uncomment require('crypto'); in the shim.js, I followed all the steps here and I tried to use rnpm link react-native-randombytes but it didn’t work as it supposed to be Screenshot 2021-04-06 at 14 42 10 Any clues what the error maybe how to resolve it?

Did you resolved the issue? or any suggestions to resolve? I have followed all the steps needed but not worked.

I also have the same issue, help would be great.

In case you are having this issue on ANDROID:

I’m using RN 041.2

rnpm link react-native-randombytes does not seem to do what it’s supposed to do. You get the error because the module is not linked.

The part that is missing is what goes in MainApplication.java, specifically:

  1. add this at the top of the file: import com.bitgo.randombytes.RandomBytesPackage;
  2. add this to the list of packages: new RandomBytesPackage()

Hope this helps!

Over a year later and i am too having this same issue. Is there a correct way of solving this and getting crypto working inside react native apps? Or is it impossible at this time? it seems many people have built crypto based apps (in React native?) and so there must be a way.

Everything i have tried i end up in one of two situations:

Either:

  1. process.version.split is undefined OR
  2. RNRandomBytes.seed is null

I am confused as to exactly which parts i should change now, i have followed multiple sets of instructions and posts about fixing it, but none have worked.

@mvayngrib I am facing the same issue when I uncomment require('crypto'); in the shim.js, I followed all the steps here and I tried to use rnpm link react-native-randombytes but it didn’t work as it supposed to be

Screenshot 2021-04-06 at 14 42 10

Any clues what the error maybe how to resolve it?

Did you resolved the issue? or any suggestions to resolve? I have followed all the steps needed but not worked.

Hi, I am also getting the same error in My Mac OS.

screen shot 2017-01-05 at 2 23 20 pm

Here is my package.json file { "name":"Test", "version":"0.0.1", "private":true, "scripts":{ "start":"node node_modules/react-native/local-cli/cli.js start", "test":"jest", "postinstall":"node_modules/.bin/rn-nodeify --install http,events,url,stream,buffer,https,crypto,vm --hack" }, "dependencies":{ "buffer":"^3.6.0", "cloudinary":"^1.5.0", "events":"^1.1.1", "https-browserify":"0.0.1", "moment":"^2.17.1", "react":"15.4.1", "react-native":"0.39.2", "react-native-calendar-picker":"^3.0.0", "react-native-crypto":"^2.0.1", "react-native-http":"github:tradle/react-native-http#834492d", "react-native-progress":"^3.2.0", "react-native-randombytes":"^2.2.0", "readable-stream":"^1.0.33", "rxjs":"5.0.2", "stream-browserify":"^1.0.0", "url":"^0.10.3", "vm-browserify":"0.0.4" }, "devDependencies":{ "babel-jest":"18.0.0", "babel-preset-react-native":"1.9.1", "eslint":"^3.12.2", "eslint-config-standard":"^6.2.1", "eslint-config-standard-react":"^4.2.0", "eslint-plugin-promise":"^3.4.0", "eslint-plugin-react":"^6.8.0", "eslint-plugin-standard":"^2.0.1", "jest":"18.0.0", "react-test-renderer":"15.4.1", "rn-nodeify":"^6.0.1" }, "jest":{ "preset":"react-native" }, "react-native":{ "crypto":"react-native-crypto", "http":"react-native-http", "https":"https-browserify", "_stream_transform":"readable-stream/transform", "_stream_readable":"readable-stream/readable", "_stream_writable":"readable-stream/writable", "_stream_duplex":"readable-stream/duplex", "_stream_passthrough":"readable-stream/passthrough", "stream":"stream-browserify", "vm":"vm-browserify" }, "browser":{ "crypto":"react-native-crypto", "http":"react-native-http", "https":"https-browserify", "_stream_transform":"readable-stream/transform", "_stream_readable":"readable-stream/readable", "_stream_writable":"readable-stream/writable", "_stream_duplex":"readable-stream/duplex", "_stream_passthrough":"readable-stream/passthrough", "stream":"stream-browserify", "vm":"vm-browserify" } }