Twilio React Native - Unable to resolve module crypto

Onaracs picture Onaracs · Apr 5, 2016 · Viewed 15.7k times · Source

I'm working on implementing the twilio package into my react-native project and when I require it in my file the project wont load and I'm seeing the following error:

Unable to resolve module crypto from /Users/[myname]/Documents/Projects/React-Native/[app-name]/node_modules/twilio/lib/webhooks.js: Unable to find this module in its module map or any of the node_modules directories under /Users/node_modules/crypto and its parent directories

I've tried installing the crypto package directly and that doesn't seem to work either.

Has anyone experienced this issue, and has a way to resolve it?

Answer

emmby picture emmby · May 28, 2016

You can use the rn-nodeify module to get crypto on react-native.

Add rn-nodeify to your devDependencies in package.json:

"devDependencies": {
  "rn-nodeify": "^6.0.1"
}

Add the following to the scripts section of the same file:

"scripts": {
  …
  "postinstall": "node_modules/.bin/rn-nodeify --install crypto --hack"
}

Be aware that rn-nodeify will modify your package.json.

More information available here: https://www.npmjs.com/package/rn-nodeify