realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.62k stars 558 forks source link

10.20.0-beta.5 Missing Constructor Error #4621

Closed djgoulart closed 1 year ago

djgoulart commented 1 year ago

How frequently does the bug occur?

All the time

Description

I did a clean install of version realm@10.20.0-beta.5 to test if it would work with reanimated2. But from the beginning I got the "Missing Realm constructor" error message.

Im using:

    "expo": "~45.0.0",
    "expo-dev-client": "~0.9.6",
    "expo-splash-screen": "~0.15.1",
    "expo-status-bar": "~1.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-web": "0.17.7",
    "realm": "10.20.0-beta.5"```

### Stacktrace & log output

```shell
Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:203:6 in guardedLoadModule
at http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.realmexpo&modulesOnly=false&runModule=true:142813:3 in global code

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError### Can you reproduce the bug?

Yes, always

Reproduction Steps

You can use the repo below as example and just configure a Sync App. https://github.com/djgoulart/realm-sync-error|url

Version

10.20.0-beta.5

What SDK flavour are you using?

Atlas App Services (auth, functions, etc.)

Are you using encryption?

No, not using encryption

Platform OS and version(s)

Android SDK 32

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

takameyer commented 1 year ago

@djgoulart Thanks for reporting! Can you confirm that node_modules/realm/react-native/android/src/main/jniLibs/ has something in it? There should be 4 folders containing librealm.so

djgoulart commented 1 year ago

@djgoulart Thanks for reporting! Can you confirm that node_modules/realm/react-native/android/src/main/jniLibs/ has something in it? There should be 4 folders containing librealm.so

@takameyer Yes there are 4 folders with 1 file each.

image

takameyer commented 1 year ago

@djgoulart Ok thanks, I am also able to reproduce this, with and without expo. Will continue to investigate why.

takameyer commented 1 year ago

@djgoulart It seems the the @realm/react is not resolving the parent dependency to realm v10.20.0-beta.5 and instead downloading its own. This related to this issue we have witnessed on iOS https://github.com/realm/realm-js/issues/4622 We will be preparing a new release for Hermes soon, as there are updates from master that need to be backported that @realm/react requires.

takameyer commented 1 year ago

Just an update. We have a PR for @realm/react which will fix the missing constructor. We still need an update to -beta to support some missing features on master

djgoulart commented 1 year ago

@takameyer I would like to help more. Askme if you need anything.

takameyer commented 1 year ago

@djgoulart we are working hard on a new release, which will solve this issue. Please be patient šŸ™‚

brunoducattii commented 1 year ago

Just to register. Similar issue that i`ve commented on React Native 0.69 new release thread. https://github.com/reactwg/react-native-releases/discussions/21#discussioncomment-2965334

brunoducattii commented 1 year ago

Just waiting for you 10.20.0-beta.6, my darling !!!!!!!!!

ChrisConway commented 1 year ago

Hello, really looking forward to the new version :) In the meantime: @takameyer can you give us any hint on how we can bypass the error for now?

I've upgraded a stable React Native project (from: "react": "^16.13.1", "react-native": "0.63.3", "realm": "^10.2.0" (+ many other libraries) --> to: "react": "^17.0.2", "react-native", "0.67.3", "realm": "^10.19.2" (I've tried different realm version also 10.20.0-beta.5)).

Currently the app is crashing on reproducible occasions, because of the "Missing Constructor" issue. This happens even when I go back to the old realm version "realm": "^10.2.0". In my prior setting, the error did not appear. It seems like the bug appears in combination with another library. I've read the comments in the React Native 0.69 new release thread. Unfortunately I'm neither using 10.20.0-beta.5 norreact-native 0.69.

Any help appreciated!

takameyer commented 1 year ago

@ChrisConway The only current workaround I have is to use Expo 44. There seems to be something in Expo 45 that comes into conflict with realm. This is, however, not an issue with the -beta branches. We are working hard to get an -rc branch completed, which should be compatible with everything.

ChrisConway commented 1 year ago

@takameyer thanks for the quick reply - unfortunately we're not using Expo. But it's good to know, maybe we'll convert. In case I'll find another way, I'll post it here. Thanks again and let me know in case I can help by providing further information.

takameyer commented 1 year ago

@ChrisConway Well it should work without expo then. However we do have known issues with react-native-reanimated v2. Does that happen to be included in your dependencies?

ChrisConway commented 1 year ago

@takameyer I'm using "react-native-reanimated": "^2.4.1"- before it was "react-native-reanimated": "^1.13.2". However downgrading reanimated back to "react-native-reanimated": "^1.13.2" seems to have fixed the issue. I can confirm that the error is no longer appearing (neither for realm 10.19.2, 10.2.0 or 10.20.0-beta.5). Thank you so much!

My current configuration: "react": "^17.0.2", "react-native", "0.67.3", "realm": "^10.20.0-beta.5", "react-native-reanimated": "^1.13.2"

Hint for anyone else coming across this issue: in order to avoid dependency problems when downgrading reanimated, I needed to disable the react-native-reanimated/plugin:

error index.js: Cannot find module 'react-native-reanimated/plugin'
...
at resolvePlugin (/Users/PathToApp/App/node_modules/@babel/core/lib/config/files/plugins.js:83:17)

-> Inside babel.config.js:

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  //plugins: ['react-native-reanimated/plugin'],
};
djgoulart commented 1 year ago

@ChrisConway @takameyer I'm using the versions below, and currently I'm not facing this issue. I'm not using reanimated at this moment.

{
    "react": "17.0.1",
    "realm": "^10.19.0",
    "@realm/react": "^0.3.0",
    "expo": "^44.0.6",
}
brunoducattii commented 1 year ago

Using RN 0.69 the problem insists even with the "react-native-reanimated" workaround suggested.

takameyer commented 1 year ago

@joaotmachado We are currently looking into compatibility issues with 0.69.0.

brunoducattii commented 1 year ago

@joaotmachado We are currently looking into compatibility issues with 0.69.0.

@takameyer could you provide any info related to the release of 10.20.0-beta.6? Our company has great expectation on it. It would able us to active the new architecture on RN 0.69 and bring the Android performance to the next level.

Thank you in advance. And let me know if you need any test support.

brunoducattii commented 1 year ago

@takameyer Still showing the same error for android with the new RC release (11.0.0-rc.0) + React Native 0.69.1 - New Architecture = True.

Missing Constructor Error

takameyer commented 1 year ago

@joaotmachado It's not currently compatible with React Native 0.69 and greater. We will update the release notes and are currently working on compatibility with the latest React Native.

tdangexo commented 1 year ago

@ChrisConway I tried to downgrade react-native-reanimated like you did but it gave me a new error A problem occurred configuring project ':react-native-reanimated'.

Configuration with name 'compile' not found.

I'm not using expo and here is my configuration: { "@realm/react": "^0.3.1", "react": "17.0.2", "react-native": "^0.68.2", "react-native-reanimated": "^1.13.4", "realm": "^10.20.0-beta.5" }

Do you know how to solve this issue? Thanks in advance !

takameyer commented 1 year ago

We have released 11.0.0-rc.1 which should be compatible with react-native 0.69.1 and react-native-reanimated

tdangexo commented 1 year ago

@takameyer I have upgraded realm to 11.0.0-rc.1 but there is always the error "Error: Missing Realm constructor. Did you run "pod install"?. I am not using Mac so I am not able to run this command

takameyer commented 1 year ago

@tdangexo that's strange. Can you try:

rm -rf node_modules
npm cache clean -f
watchman watch-del-all
rm -rf $TMPDIR/metro*
rm -rf $TMPDIR/react-native*
npm install

Also, does this directory exist? node_modules/@realm/react/node_modules/realm And finally, can you share your current package.json

tdangexo commented 1 year ago

@takameyer I tried all given instructions but nothing works. The directory realm exists. Here is my package.json{ "name": "exo.operator", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { "@realm/react": "^0.3.1", "@reduxjs/toolkit": "^1.8.2", "react": "17.0.2", "react-native": "^0.68.2", "react-native-config": "^1.4.6", "react-native-elements": "^3.4.2", "react-native-encrypted-storage": "^4.0.2", "react-native-gesture-handler": "^2.5.0", "react-native-get-random-values": "^1.8.0", "react-native-reanimated": "^2.9.1", "react-native-safe-area-context": "^4.3.1", "react-native-screens": "^3.15.0", "react-native-vector-icons": "^9.2.0", "react-navigation": "^4.4.4", "react-navigation-stack": "^2.10.4", "react-navigation-tabs": "^2.11.2", "react-redux": "^8.0.2", "realm": "^11.0.0-rc.1" }, "devDependencies": { "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^2.0.0", "@types/jest": "^26.0.23", "@types/react-native": "^0.67.3", "@types/react-test-renderer": "^17.0.1", "@typescript-eslint/eslint-plugin": "^5.17.0", "@typescript-eslint/parser": "^5.17.0", "babel-jest": "^26.6.3", "eslint": "^7.32.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "^0.67.0", "react-test-renderer": "17.0.2", "typescript": "^4.4.4" }, "resolutions": { "@types/react": "^17" }, "jest": { "preset": "react-native", "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] } }

takameyer commented 1 year ago

@tdangexo what version of node and npm are you using?

tdangexo commented 1 year ago

@takameyer node 16.15.1 and npm 8.11.0. In fact when running npm install, it gave me "Could not resolve dependency peer react-native-safe-area-context@"^3.1.9" from react-native-elements@3.4.2

node_modules/react-native-elementsreact-native-elements@"^3.4.2" from the root project So i ran npm install --legacy-peer-deps. Maybe it did not work due to this dependency issue?

takameyer commented 1 year ago

@tdangexo That's possible. I'll see if I can reproduce this. You building for Android, correct?

tdangexo commented 1 year ago

@takameyer yeahh I'm building for Android. Thanks a lot for your help !

takameyer commented 1 year ago

@tdangexo I am able to reproduce this using our template app and simply installing realm@11.0.0-rc.1. So we can rule out the --legacy-peer-deps idea. It's possible updating React Native will make the issue go away. I'll verify this.

takameyer commented 1 year ago

Verified. Try upgrading to the latest React Native version if you want to use realm@11.0.0-rc.1.

djgoulart commented 1 year ago

@takameyer Is the realm@11.0.0-rc.1 compatible with expo SDK 44 ?

tdangexo commented 1 year ago

@takameyer Thank you very much, the missing constructor error disappeared. However I can not open the app properly, each time I click on the app, it crashes and returns to the main screen. Is it due to the upgrade of React Native from 0.68 to 0.69?

takameyer commented 1 year ago

@djgoulart unfortunately no. realm@11.0.0-rc.1 is only compatible with react-native@0.69.1. Expo SDKs have a pinned react-native version. But it is possible to upgrade React Native manually in an Expo project. I'll try and get an idea from Expo on when they will update their underlying react-native version.

@tdangexo did you follow all the steps to upgrade? See (https://react-native-community.github.io/upgrade-helper/?from=0.68.2&to=0.69.1)

brunoducattii commented 1 year ago

@takameyer.

I still got the error: Missing Realm constructor. Did you run "pod install"?

takameyer commented 1 year ago

We just pinpointed an issue in @realm/react which was loading a different version of realm, causing Android builds to fail. Please try updating @realm/react to version 0.3.2.

takameyer commented 1 year ago

@djgoulart I have just tested with Expo SDK 45. If you install @realm/react@0.3.2 and realm@11.0.0-rc.0, it will work šŸ™‚

djgoulart commented 1 year ago

@djgoulart I have just tested with Expo SDK 45. If you install @realm/react@0.3.2 and realm@11.0.0-rc.0, it will work slightly_smiling_face

@takameyer Great news! I will make a test with this versions. Currently im using the sack below and im having an issue with the toJSON function.

{
"@realm/react": "^0.3.0",
"expo": "^44.0.6",
"react": "17.0.1",
"realm": "^10.19.0",
"react-native": "0.64.3",
}
djgoulart commented 1 year ago

We just pinpointed an issue in @realm/react which was loading a different version of realm, causing Android builds to fail. Please try updating @realm/react to version 0.3.2.

@takameyer I was facing this issue, but yesterday it starts to building normaly. Still having some error logs about some @realm/react internal libs (maybe) being deprecated, but until now it's working.

image

brunoducattii commented 1 year ago

@takameyer

I tried to follow the steps from https://www.mongodb.com/docs/realm/sdk/react-native/use-realm-react/#setup-realm-react, to install @realm/react in my app, but without success. The error continues.

Version: @realm/react: ^0.3.2

takameyer commented 1 year ago

@joaotmachado What version of realm and react-native are you using?

brunoducattii commented 1 year ago

@takameyer

Here is my package.json:

{
  "name": "MyApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "backgroundTests": "jest --verbose ./src/services/background",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@apollo/client": "3.6.9",
    "@MyApp/react-native-google-cloud-tts": "^0.1.13",
    "@MyApp/react-native-selectable-text": "^0.0.24",
    "@react-native-async-storage/async-storage": "^1.17.4",
    "@react-native-community/clipboard": "^1.5.1",
    "@react-native-community/netinfo": "^9.3.0",
    "@react-native-community/slider": "^4.2.2",
    "@react-native-firebase/analytics": "14.9.4",
    "@react-native-firebase/app": "14.9.4",
    "@react-native-firebase/crashlytics": "14.9.4",
    "@react-native-firebase/in-app-messaging": "14.9.4",
    "@react-native-firebase/messaging": "14.9.4",
    "@react-navigation/bottom-tabs": "^6.3.2",
    "@react-navigation/native": "^6.0.11",
    "@react-navigation/native-stack": "^6.7.0",
    "@react-navigation/stack": "^6.2.2",
    "@realm/react": "^0.3.2",
    "@sentry/react-native": "^4.1.3",
    "@types/react-native-vector-icons": "^6.4.10",
    "@types/react-navigation": "^3.4.0",
    "formik": "^2.2.6",
    "graphql": "^16.5.0",
    "graphql-tag": "^2.11.0",
    "lottie-react-native": "^5.1.3",
    "npm": "^8.14.0",
    "npm-check-updates": "^15.2.6",
    "ramda": "^0.28.0",
    "react": "18.2.0",
    "react-dom": "^18.2.0",
    "react-native": "0.69.1",
    "react-native-animatable": "^1.3.3",
    "react-native-code-push": "^7.0.4",
    "react-native-device-info": "^10.0.1",
    "react-native-dropdown-picker": "^5.4.2",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^2.5.0",
    "react-native-hyperlink": "0.0.19",
    "react-native-iap": "^8.2.1",
    "react-native-in-app-review": "^4.1.1",
    "react-native-keyboard-aware-scroll-view": "^0.9.5",
    "react-native-linear-gradient": "^2.6.2",
    "react-native-modalize": "^2.0.13",
    "react-native-open-notification": "^0.1.4",
    "react-native-pell-rich-editor": "^1.8.8",
    "react-native-portalize": "^1.0.7",
    "react-native-progress": "^5.0.0",
    "react-native-responsive-screen": "^1.4.2",
    "react-native-safe-area-context": "^4.3.1",
    "react-native-screens": "^3.15.0",
    "react-native-share": "^7.6.6",
    "react-native-size-matters": "^0.4.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sound": "^0.11.2",
    "react-native-splash-screen": "^3.3.0",
    "react-native-svg": "^12.3.0",
    "react-native-system-setting": "^1.7.6",
    "react-native-vector-icons": "^9.1.0",
    "react-native-webview": "11.17.2",
    "realm": "11.0.0-rc.1",
    "styled-components": "^5.2.1",
    "text-encoding": "^0.7.0",
    "use-http": "^1.0.18",
    "yarn": "^1.22.10",
    "yup": "^0.32.9",
    "zustand": "^4.0.0-rc.1"
  },
  "devDependencies": {
    "@babel/core": "^7.13.10",
    "@babel/plugin-proposal-class-properties": "^7.13.0",
    "@babel/plugin-transform-flow-strip-types": "^7.13.0",
    "@babel/runtime": "^7.13.10",
    "@react-native-community/cli-debugger-ui": "^8.0.0",
    "@react-native-community/eslint-config": "^2.0.0",
    "@types/jest": "^26.0.20",
    "@types/ramda": "^0.27.39",
    "@types/react": "^18.0.15",
    "@types/react-native": "^0.69.3",
    "@types/react-native-background-downloader": "^2.3.3",
    "@types/react-native-background-timer": "^2.0.0",
    "@types/react-native-dotenv": "^0.2.0",
    "@types/react-native-share": "^3.3.1",
    "@types/react-native-snap-carousel": "^3.8.2",
    "@types/react-test-renderer": "17.0.1",
    "@types/styled-components": "^5.1.15",
    "@types/styled-components-react-native": "^5.1.1",
    "@types/text-encoding": "^0.0.35",
    "@types/yup": "^0.29.11",
    "@typescript-eslint/eslint-plugin": "^4.18.0",
    "@typescript-eslint/parser": "^4.18.0",
    "babel-jest": "^28.1.3",
    "babel-plugin-module-resolver": "^4.1.0",
    "eslint": "^8.19.0",
    "eslint-plugin-prettier": "^4.2.1",
    "jest": "^28.1.3",
    "metro-react-native-babel-preset": "^0.71.3",
    "patch-package": "^6.4.7",
    "postinstall-postinstall": "^2.1.0",
    "prettier": "^2.2.1",
    "react-native-dotenv": "^2.5.3",
    "react-native-flipper": "^0.124.0",
    "react-native-flipper-zustand": "^1.0.2",
    "react-native-svg-transformer": "^1.0.0",
    "react-test-renderer": "18.0.0",
    "typescript": "^4.7.4"
  },
  "jest": {
    "preset": "react-native",
    "moduleNameMapper": {
      "^services(.*)$": "<rootDir>/src/services$1"
    },
    "transform": {
      "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
    },
    "testPathIgnorePatterns": [
      "/node_modules/",
      "./dist"
    ],
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}
brunoducattii commented 1 year ago

I tried everything this realm with the new arch doesn't work here. =(

edgarriii commented 1 year ago

Hey, @takameyer, I'm facing such issue. When I tried to use Realm.open() my app crashes immediately without any logs in metro. I'm using RN v0.69.2 and react-native-reanimated v2.9.1

image
takameyer commented 1 year ago

@edgarriii Please consult our compatability matrix. You will either need to downgrade realm to 11.0.0-rc.1 or upgrade React Native. I would recommend using the latest React Native (v70) and the latest Realm (v11)

takameyer commented 1 year ago

Closing this issue, as this has strayed away from the original problem, which has been solved. If you are still seeing a similar issue, please open a new issue and provide as many details as you can.