I spent 2 days to solve the issue, I have inlineRequires: false,
in metro config and changing it breaks the app.
I installed yarn add react-native-get-random-values
.
Then imported react-native-get-random-values
before crypto-js
but it didn't work.
After hours of debugging, I found it's Babel's compiling order issue. crypto-js
is always compiled earlier than react-native-get-random-values
. In another word crypto-js
looks for global.crypto
before react-native-get-random-values
assigns it. import
s compile with higher priority than the rest of codes.
My file was:
import 'react-native-get-random-values'
import crypto from 'crypto-js`
The fix was lowering the compile order of crypto-js
to make sure it compiles after global.crypto
is assigned:
import 'react-native-get-random-values'
const crypto = require('crypto-js')
react-native-qrcode-generator
?