title: Error: attempted to import the Node standard library module "crypto". It failed
body: <p>I was going to use <code>ethereumjs-wallet</code>. But I decided to use <code>ethereumjs-wallet-react-native</code> because it's for the web. If you look at <a href="https://github.com/WoeOm/ethereumjs-wallet-react-native" rel="nofollow noreferrer">the link</a>, it says <code>import</code> the two modules. So I took two modules and tried to <code>import</code> them, but there was a problem.</p>
  
  <p>an error-causing code:</p>
  
  <pre class="lang-js prettyprint-override"><code>import { asyncRandomBytes } from 'react-native-secure-randombytes'
  import safeCrypto from 'react-native-safe-crypto'
  
  window.randomBytes = asyncRandomBytes
  window.scryptsy = safeCrypto.scrypt
  </code></pre>
  
  <p>Errormessage:</p>
  
  <blockquote>
    <p>Unable to resolve module "react-native-secure-randombytes"</p>
  </blockquote>
  
  <p>I wanted to solve this problem, but I couldn't solve it, so I decided to take a detour.</p>
  
  <p>Error Resolved Code:</p>
  
  <pre class="lang-js prettyprint-override"><code>import safeCrypto from "react-native-fast-crypto";
  const { RNRandomBytes } = NativeModules;
  
  window.randomBytes = RNRandomBytes.randomBytes;
  window.scryptsy = safeCrypto.scrypt;
  </code></pre>
  
  <p>This may cause problems later, but it's settled for now. However, there was another problem when we called up and executed <code>ethereumjs-wallet-react-native.</code></p>
  
  <p>errormessage:</p>
  
  <blockquote>
    <p>The package at "node_modules/ethereumjs-wallet-react-native/index.js"
    attempted to import the Node standard library module "crypto". It
    failed because React Native does not include the Node standard
    library. Read more at
    <a href="https://docs.expo.io/versions/latest/introduction/faq/#can-i-use-nodejs-packages-with-expo" rel="nofollow noreferrer">https://docs.expo.io/versions/latest/introduction/faq/#can-i-use-nodejs-packages-with-expo</a></p>
  </blockquote>
  
  <p>So I downloaded <code>crypto-browserify</code>, but it didn't work.</p>
  
  <p>Code that attempted to resolve</p>
  
  <pre class="lang-js prettyprint-override"><code>import safeCrypto from "react-native-fast-crypto";
  const { RNRandomBytes } = NativeModules;
  import Wallet from "ethereumjs-wallet-react-native";
  var crypto = require("crypto-browserify");
  
  window.randomBytes = RNRandomBytes.randomBytes;
  window.scryptsy = safeCrypto.scrypt;
  ...
   async componentDidMount() {
      const wallet = await Wallet.generate();
    }
  </code></pre>
  
  <p>this is package.json:</p>
  
  <pre><code>  "dependencies": {
      "crypto-browserify": "^3.12.0",
      "ethereumjs-wallet-react-native": "^0.6.7",
      "expo": "^32.0.0",
      "expokit": "32.1.1",
      "react": "16.5.0",
      "react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
      "react-native-fast-crypto": "^1.8.1",
      "react-native-randombytes": "^3.5.2"
    },
    "devDependencies": {
      "babel-preset-expo": "^5.0.0"
    },
  </code></pre>
  
  <p>The code for "ethereumjs-wallet-react-native/index.js" is located on <a href="https://github.com/WoeOm/ethereumjs-wallet-react-native" rel="nofollow noreferrer">the link</a> in my article.</p>
  
  <p>Please help us. Thank you in advance.</p>