Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twilio React Native - Unable to resolve module crypto

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?

like image 620
Onaracs Avatar asked Apr 05 '16 00:04

Onaracs


1 Answers

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

like image 128
emmby Avatar answered Sep 28 '22 03:09

emmby