question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Here is a better alternative to rn-nodeify

See original GitHub issue

At the beginning of the quick start for Dapps (React Native) it proposes that folks use npx rn-nodeify --install --hack. This is problematic for a couple of reasons:

  1. It doesn’t appear to work. I was not able to get it to work despite much effort. I finally gave up after applying sed hacks and many rm -rf node_mdules and pod installs.
  2. It’s an ugly hack. (See rn-nodeify author’s remarks). Not that co-opting the bundler to replace all your nodejs modules is not a hack, but at least its a hack that more or less the entire web dev world depends on. And even if rn-nodeify did work, it has consequences and is fragile.

Here is a better way:

Use the new metro bundler to do essentially what browserfy and webpack do. Here’s how I got it to work:

In package.json:

  "dependencies": {
    . . . 
    "@react-native-async-storage/async-storage": "^1.15.17",
    "@walletconnect/react-native-dapp": "^1.7.1",
    "react-native-qrcode-svg": "6.0.6",
    "react-native-randombytes": "^3.6.1",
    "react-native-svg": "9.6.4"
  },
  "devDependencies": {
    . . . 
    "node-libs-react-native": "^1.2.1",
  },

The various react-native* deps are because even though new RN is good about having pod install take care of installing pods for native modules, it doesn’t detect second- and greater order native deps. Note the specific versions. These are the versions that @walletconnect transitively requires. Blindly doing npm install -s react-native-svg for example will result in 2 versions of the SVG package being brought in, which results in a crash at startup.

The important one is the devDependency for node-libs-react-native

Next, create or edit metro.config.js :

module.exports = {
  resolver: {
    extraNodeModules: require("node-libs-react-native")
  },
  . . . 
};

This is the magic: It says: hey, metro, if you see, oh, say import * from "crypto"; and you can’t find crypto, go ask node-libs-react-native, which then hooks up react-native-crypto.

There’s one more little step, which is that Node.js modules often depend on certain globals. You hook these up by adding:

require("node-libs-react-native/globals.js");
 . . . 

at the top of index.js

It was just about that simple. I would strongly encourage to update the documentation for this amazing codebase and enable more folks to get it working faster. rn-nodeify is really an abominable hack, and whereas a better cleaner solution exists, now that the metro bundler has become sufficiently enhanced.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:42
  • Comments:23

github_iconTop GitHub Comments

3reactions
gate3commented, Jun 1, 2022

Just putting this here in case anybody needs it… its bootstrapped and ready to go. Already has walletConnect and ethersjs installed.

Bare Workflow https://github.com/weedle-app/weedle-expo-bare-workflow

Managed Workflow https://github.com/weedle-app/weedle-expo-managed-workflow

1reaction
aindongcommented, Sep 6, 2022

Just putting this here in case anybody needs it… its bootstrapped and ready to go. Already has walletConnect and ethersjs installed.

Bare Workflow https://github.com/weedle-app/weedle-expo-bare-workflow

Managed Workflow https://github.com/weedle-app/weedle-expo-managed-workflow

Thank you @gate3 this is the best solution reference to follow 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is react-native-crypto and rn-nodeify the go to method ... - Reddit
Seems like everywhere I look, the go to method is to use react-native-crypto and rn-nodeify. This seems like a huge hack and is...
Read more >
Use stream-browserify with expo - react native - Stack Overflow
This answer rn-nodeify install that i have posted should work. Except Step 1 & Step 5 follow all steps ...
Read more >
js-threads-client
Go to the docs for more about Textile. ... Here are some helpful pointers if you find issues testing it out. ... rn-nodeify...
Read more >
@deficonnect/react-native-dapp - npm
... support for Web3 in an existing project by using npx rn-nodeify --install --hack . For more details, check out the documentation.
Read more >
User Buckets in React Native | Documentation - Textile Docs
Read about rn-nodeify here. Next, you need to run: ./node_modules/.bin/rn-nodeify --install.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found