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

importing matic.js throws an exception in react-native #336

Closed
rawatnaresh opened this issue May 6, 2022 · 2 comments
Closed

importing matic.js throws an exception in react-native #336

rawatnaresh opened this issue May 6, 2022 · 2 comments

Comments

@rawatnaresh
Copy link

Describe the bug

Error: Unable to resolve module events from /matic/node_modules/@ethereumjs/common/dist.browser/index.js: events could not be found within the project or in these directories

Hint

  • created a new react-native project using npx react-native init MyApp

  • installed

    • @maticnetwork/maticjs
    • @maticnetwork/maticjs-ethers
    • @maticnetwork/maticjs-web3
  • imported and use web3 plugin

import {use} from '@maticnetwork/maticjs';
import {Web3ClientPlugin} from '@maticnetwork/maticjs-web3';

// install web3 plugin
use(Web3ClientPlugin);
  • Starting the app throws an exception

Screen Shot 2022-05-06 at 17 00 15

@ujjwalgupta94
Copy link
Contributor

ujjwalgupta94 commented May 11, 2022

ok, will have a look.

@ParthPatel-DA
Copy link

Hi @rawatnaresh,

As we debug your project repo and we found that react-native is not running on top of node(run on javascript core) that's why some of the packages won't available. So, you need to install those packages manually by yourself in your project and the issue will be resolved. The steps are provided below for your reference.

Steps:

npm i assert

npm i events

npm i stream

npm i react-native-crypto

npm i react-native-randombytes

react-native link react-native-randombytes

npm i --save-dev tradle/rn-nodeify

./node_modules/.bin/rn-nodeify --hack --install

Then, import shim.js in your index.js file.

You can see the project running.

Screen Shot 2022-05-18 at 17 04 52PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants