Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Web3js react native shim package #7313

Closed
avkos opened this issue Oct 8, 2024 · 3 comments
Closed

Create Web3js react native shim package #7313

avkos opened this issue Oct 8, 2024 · 3 comments
Assignees
Labels
4.x 4.0 related Investigate P2 Medium severity bugs

Comments

@avkos
Copy link
Contributor

avkos commented Oct 8, 2024

Related to the investigation in issue #7198

  • run the test on react-native (expo) and check what extra shims need to be installed to make it work
  • create a separate package web3js-react-native-shims and include everything that should be installed to make web3js work on react-native
@krzysu
Copy link
Contributor

krzysu commented Nov 19, 2024

I figured out why React Native works only with the default import from web3.js and not with named imports. The issue lies in how React Native’s Metro bundler resolves modules. It prioritizes the "browser" field in a package’s package.json for module resolution. See the Metro documentation here.

In the case of web3.js, the "browser" field points to a minimized file:

"browser": "./dist/web3.min.js"

@krzysu
Copy link
Contributor

krzysu commented Nov 20, 2024

I discovered that the react-native-quick-crypto package resolves all React Native compatibility issues for web3.js. This means we don’t need a dedicated shim package; instead, we can add a dedicated React Native setup page to the documentation for clarity.

Looking ahead, future versions of web3.js should aim to eliminate dependencies on Node.js-specific modules like crypto, buffer, and stream. This will ensure better compatibility across JS environments.

@krzysu
Copy link
Contributor

krzysu commented Dec 3, 2024

There is only one package required to make web3.js work with React Native: react-native-quick-crypto. This eliminates the need for a special web3 shim. The documentation page will suffice, so I’m closing this in favor of #7314.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Investigate P2 Medium severity bugs
Projects
None yet
Development

No branches or pull requests

4 participants
@krzysu @avkos @mconnelly8 and others