yarn add react-native-crypto react-native-randombytes
安装兼容工具
yarn add --dev tradle/rn-nodeify
link
react-native link
生成兼容js
./node_modules/.bin/rn-nodeify --hack --install
然后在 App.js 中引入
import './shim.js' import crypto from 'crypto'
如果报错
added 120 packages from 133 contributors, removed 95 packages and updated 1064 packages in 156.737s /Users/Easy/Playground/lm1/node_modules/rn-nodeify/cmd.js:74 if (err) throw err ^ Error: ENOENT: no such file or directory, open '/Users/Easy/Playground/lm1/node_modules/rn-nodeify/shim.js'
报错以后怎么办呢?
react-native link
然后 重新装 rn-nodefiy
yarn add --dev tradle/rn-nodeify
再运行
./node_modules/.bin/rn-nodeify --hack --install