Open avkos opened 1 month ago
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"
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.
Related to the investigation in issue #7198