Reputation: 491
Steps to reproduce:
create-react-native-app proj && cd proj && npm i
Installing package that is using crypto. Performing steps listed at https://www.npmjs.com/package/react-native-crypto :
npm i -S react-native-crypto && npm i -S react-native-randombytes
react-native link react-native-randombytes
Got a warning for react-native link failure, however after the following hack crypto dependancy is no longer a problem:
npm i --save-dev tradle/rn-nodeify
./node_modules/.bin/rn-nodeify --hack --install
Adding import './shim.js'
into the App.js
yarn run ios
Got a problem like here: https://github.com/mvayngrib/react-native-randombytes/issues/13
undefined is not an object (evaluating 'RNRandomBytes.seed')
I can't update npm and node due to some of the used package restrictions
MacOS 10.12, Node 8.0.0, npm 5.0
EDIT:
RNRandomBytes are initialized as let RNRandomBytes = require('react-native').NativeModules.RNRandomBytes
init
is the first place where RNRandomBytes is accessed in react-native-randombytes imported from react-native-crypto imported from twitter nacl
EDIT2: After creating project via react-native init
linking phase completed successfully:
rnpm-install info Linking react-native-randombytes android dependency
rnpm-install info Android module react-native-randombytes has been successfully linked
rnpm-install info Linking react-native-randombytes ios dependency
rnpm-install info iOS module react-native-randombytes has been successfully linked
import './shim.js'
for this sample project is in the index.js instead of App.js
But the error was the same
Upvotes: 3
Views: 5636
Reputation: 35950
The RNRandomBytes
variable is not defined, because it should be exported by a native module, and you haven't linked the module.
The react-native link
step fails, because you've initialised your project using create-react-native-app
, which is based on Expo, and does not allow linking custom native dependencies.
If you want to use this library (or other React Native libraries with native dependencies) you'll need to either eject from the Expo app, or initialise your project with react-native init
.
You can read more about the difference between create-react-native-app
and react-native init
here: whats the real diff between "create-react-native-app myproject" and "react-native init myproject".
Upvotes: 4