react-native-crypto: TypeError: undefined is not a constructor (evaluating 'new brorand.Rand()')

I am using react-native-crypto with rn-nodeify. but got following error

Requiring module "react-native-crypto/index.js", which threw an exception: TypeError: undefined is not a constructor (evaluating 'new brorand.Rand()')

screenshot from 2017-06-27 19-39-34

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

Hello! I’ve resolved this issue by importing crypto just after shim.js This is my app.js

import "./shim";
import crypto from "crypto";
import React from "react";
import App from "./js/App";

export default class App1 extends React.Component {
  render() {
    return <App />;
  }
}

@micimize great to hear! Yes, for some cases rewrite-require is enough. But due to a number of incompatibilities between the react-native packager and webpack/browserify, there’s a number of hacks/patches rn-nodeify uses (see https://github.com/tradle/rn-nodeify/blob/master/pkg-hacks.js)

Not sure if everyone has got this working yet but I had the same problem and after messing with it for a while I got it working.

  1. rm -rf node_modules
  2. rm shim.js
  3. npm install
  4. rn-nodeify --hack --install

And it worked! A couple things to note.

  1. I had hacked bignumber.js (that’s required by web3.js) a while back to work with the proper crypto library, but removed the hack since rn-nodeify solves the issue.
  2. When building from xcode on a simulator or device I made sure to do a hard clean of the build directory (option + shift + command + k)

I’m not 100% sure what combination of all of this worked but it’s currently working for me.