jeremyscalpello / node-2fa

Easy 2-Factor Integration For Node.JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to resolve module 'crypto'

rhrahul opened this issue · comments

Hey,

I am facing this issue,

error: bundling failed: Error: Unable to resolve module "crypto" from "..\myProject\node_modules\node-2fa\index.js": Module "crypto" does not exist in the Haste module map

I am using React Native v0.57.7

Any Suggestions Please ?

Hey,

React Native runs on JavaScriptCore, which doesn't have the crypto module built-in, as it's a Node module.

The best way to get it to work in React Native would be to install the crypto-browserify and babel-plugin-rewrite-require modules and add the following code to your .babelrc file, which will alias all calls to require('crypto') to require('crypto-browserify').

{
  "presets": ["react-native"],
  "plugins": [
    ["babel-plugin-rewrite-require", {
      "aliases": {
        "crypto": "crypto-browserify"
      }
    }]
  ]
}

Hope that helps!

Thanks for answer @jeremyscalpello 👍