Moralis not working in react native 0.64.x and after

@phyx1u5 i changed the packages like you mentioned but i still get the same error as above.

  "dependencies": {
    "@ethersproject/shims": "^5.5.0",
    "ethers": "^5.5.4",
    "moralis": "0.0.99",
    "patch-package": "^6.4.7",
    "postinstall-postinstall": "^2.1.0",
    "react": "17.0.2",
    "react-moralis": "0.2.7",
    "react-native": "0.67.2",
    "react-native-get-random-values": "^1.7.2"
  }

and node v14.18.3

Could you maybe upload a repo?
What version of node are you using?

I highly recommend you try the following:
clone the react native boiler plate and try get that working. if you get stuck watch the YouTube vid.
https://youtu.be/dZYSr9UPdfQ

once you get it working, you can then try upgrade react native following the instructions at their site.
https://reactnative.dev/docs/upgrading
note if
npx react-native upgrade
fails then you will have to follow the manual instructions.

after upgrade then you can edit the EventEmitter file as I mentioned.
you will have to edit the file every time you run yarn add for every new package as it will rewrite the file.

don’t for forget to

cd ios && pod install

if you are building for ios

a few other things, to note:
npx react-native run-android/run-ios

didn’t work for me, I always had to build via android studio or xcode + running npx react-native start in a separate terminal

Hi @malik , i am trying to use Moralis in react native . Following are the details of my dependencies i.e versions
“@ethersproject/shims”: “^5.5.0”,
“ethers”: “^5.5.4”,
“moralis”: “0.0.99”,
“patch-package”: “^6.4.7”,
“react”: “17.0.2”,
“react-moralis”: “0.2.7”,
“react-native”: “0.67.3”,
“react-native-get-random-values”: “^1.7.2”

Whenever i import MoralisProvider and try to use it , app returns following error
Error: Unable to resolve module events from /home/mtalha/NewDapp/node_modules/moralis/lib/browser/MoralisWeb3.js: events could not be found within the project or in these directories:
node_modules/moralis/node_modules
node_modules

I have tried all of the available solutions but of no avail. Pleae help me out in that .

have you tried following my steps?

Hi,
I tried react-native boilerplate it’s working
But when I try to integrate it into my app I am getting the same error as mentioned above
My project specs:
React Native version. 0.60.6
Moralis version 0.0.99

Hey thank you for your solution.

The problem is that the boilerplate is using web3.js and not ethers.js. we need it to work with ethers.js. And then on top of that i need to implement it on our react-native init app that has already had a lot of development made on it.

moralis says it works with ethers.js so im confused as to why it doesnt.

so this issue

TypeError: undefined is not an object (evaluating ‘EventEmitter.prototype.addListener’)

is linked to the RN version you guys use? when will it be up to date?
Also, for simple things like a DB call, none of that should be necessary, an API endpoint should be callable via curl theoretically no?

1 Like

do you have the versions that do work together? because i think there is a way to use different version of react in your react app.

I don’t know… I am just trying to call the DB, it’s mind boggling to me that it’s that complex…
Here is my package.json

"dependencies": {
    "@expo/vector-icons": "^12.0.0",
    "@hookstate/core": "^3.0.13",
    "@magic-sdk/react-native": "^8.2.0",
    "@react-native-community/async-storage": "^1.12.1",
    "@react-native-firebase/app": "^14.5.0",
    "@react-native-firebase/storage": "^14.5.0",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/native-stack": "^6.1.0",
    "expo": "~44.0.0",
    "expo-asset": "~8.4.4",
    "expo-constants": "~13.0.0",
    "expo-dev-client": "~0.8.4",
    "expo-document-picker": "~10.1.3",
    "expo-font": "~10.0.4",
    "expo-linking": "~3.0.0",
    "expo-splash-screen": "~0.14.0",
    "expo-status-bar": "~1.2.0",
    "expo-web-browser": "~10.1.0",
    "moralis": "^1.4.0",
    "node-libs-browser": "^2.2.1",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-moralis": "^1.3.2",
    "react-native": "0.64.3",
    "react-native-progress": "^5.0.0",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "~3.10.1",
    "react-native-svg": "^12.3.0",
    "react-native-track-player": "^2.1.2",
    "react-native-web": "0.17.1",
    "react-native-webview": "^11.17.2",
    "web3": "^1.7.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.64.12",
    "jest": "^26.6.3",
    "jest-expo": "~44.0.1",
    "react-test-renderer": "17.0.1",
    "typescript": "~4.3.5"
  },

thanks i am quickly going to try your react and react native versions and see if i can get it to work on my side.

1 Like

did you every try my solution?
add _ before Event, it should work. just make sure Moralis version is 0.0.99

hi, I appreciate but the current version is 1.4, I don’t want to use a workaround whereas I am just testing Moralis offer. If s imple DB call needs workarounds then it doesn’t make sense (not that I doubt it will work, but I want something stable)

believe me I have spent many hours trying to get latest version to work, but I couldn’t get it working. so for now I’m just using 0.0.99. hopefully the Moralis team update their react native boiler plate for the latest version of Moralis in the near future.

I have requested the team to update the boilerplate code

agreed with @taha, the team should update the boilerplate. And normally they will find incompatibilities between different lib versions (which is our issue) and fix their SDK cause that’s the root cause.
Also I don’t know if team members like @cryptokid could let them know they should decorelate the Web3 part of the SDK (like Wallet connect) and the Web2 part (like getting data from the Sync Server, events) cause they should not be that tightly coupled…or to provide an API endpoint

@talhabinkhalil can you add this postinstall script to your package.json like what we have in the boilerplate?
"postinstall": "node_modules/.bin/rn-nodeify --install crypto,http,https,os,assert,url,stream,events --yarn"

@ibox @loekTheDreamer @phyx1u5 I created a PR updating Moralis SDK and React-Native to latest. Can you check and let me know if it works for you?

thanks Gen I will try it soon, I am developing for android as well, are there any changes required to android files?

1 Like

Hi, it doesn’t. Did you try it yourself? I already mentioned in Discord that the last version doesn’t fix it

@ibox Yes I just created the PR last night. Please try the PR for now and if it works, it will be merged in the main branch.