walletconnect-monorepo: React Native: crypto module problem
Crypto dependency problem
on React Native
Having upgraded to React Native 0.65.1, I now get the following error when building the app:
error: Error: Unable to resolve module crypto from /path/project/node_modules/@walletconnect/randombytes/dist/cjs/node/index.js: crypto could not be found within the project or in these directories:
node_modules
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
5 | Object.defineProperty(exports, "__esModule", { value: true });
6 | exports.randomBytes = void 0;
> 7 | const crypto_1 = __importDefault(require("crypto"));
| ^
8 | const encoding_1 = require("@walletconnect/encoding");
9 | function randomBytes(length) {
10 | const buf = crypto_1.default.randomBytes(length);
Some discussion about this on stackoverflow: https://stackoverflow.com/a/64363788
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 20
following the workflow from react-native-crypto https://github.com/tradle/react-native-crypto
install peer deps
on RN >= 0.60, instead do: cd iOS && pod install
install latest rn-nodeify
install node core shims and recursively hack package.json files in ./node_modules to add/update the “browser”/“react-native” field with relevant mappings
it should work fine
This is the issue of react native running in browser environment, not having the Node.js builtin deps. See here or here. To fix:
npm i --save-dev rn-nodeifyAdd postinstall script to nodemodules:
Then
npm install.Note if you have this issue with multiple Node.js builtin packages (ie.
streams) you can hack them inline as"postinstall": "node_modules/.bin/rn-nodeify --install crypto --hack && node_modules/.bin/rn-nodeify --install stream --hack"This help me, but then i have this issue “Invariant Violation: Tried to register two views with the same name RNSVGRect” and i solve with putting this on the package.json:
"overrides": { "react-native-svg": "^13.4.0" }, "resolutions": { "react-native-svg": "^13.4.0" },this repo has solved this problem
I was able to get past this by employing the sed hacks from https://github.com/WalletConnect/walletconnect-monorepo/issues/595#issuecomment-992510359 . But that just leads to:
But now I’m getting the following errors: