React Native: crypto module problem
See original GitHub issueCrypto 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
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:18
Top Results From Across the Web
Unable to resolve module crypto in reactnative - Stack Overflow
Crypto is a node js module, when React Native is run - it uses Javascript Core. Crypto isn't include within this. When I...
Read more >Unable to resolve module crypto - DEV Community
The gist of it is that React Native does not use the Node runtime environment and thus does not have access to specific...
Read more >Can't resolve 'crypto' in node_modules/bson/dist react
I'm using realm-web on my react app to build a simple task reminder app. ... The app is running fine but I'm having...
Read more >unable to resolve module assets react native - You.com
1. I had the same problem, I fixed that by below steps: 1-> delete node_modules by: rm -rf node_modules. 2-> delte Pods ...
Read more >Crypto - Expo Documentation
If you're installing this in a bare React Native app, you should also follow these ... return ( <View style={styles.container}> <Text>Crypto Module ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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-nodeify
Add 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"