realm-js: Incompatible with React Native Autolinking (React Native v0.60)

Goals

Use the Realm.js with React Native Autolinking correctly.

Expected Results

Don’t show warning information.

Let the CocoaPods don’t show warning after executing pod install.

Actual Results

After the pod install, it shows the following warning:

[!] use_native_modules! skipped the react-native dependency 'realm'. No podspec file was found.
    - Check to see if there is an updated version that contains the necessary podspec file
    - Contact the library maintainers or send them a PR to add a podspec. The react-native-webview podspec is a good example of a package.json driven podspec. See
    https://github.com/react-native-community/react-native-webview/blob/master/react-native-webview.podspec
    - If necessary, you can disable autolinking for the dependency and link it manually. See
    https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-disable-autolinking-for-unsupported-library

Steps to Reproduce

cd ${REACT_NATIVE_PROJECT_ROOT_PATH}
npm install --save realm
cd ios && pod install & cd ..

Version of Realm and Tooling

  • Realm JS SDK Version: realm-js 2.29.1
  • Node or React Native: React Native v0.60.3
  • Client OS & Version: iOS 12.2
  • Which debugger for React Native: None

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 35
  • Comments: 40 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Hey everyone. There are already plans to fix this soon.

I’m getting the same error as @excitedcat. Has anyone found a solution?

I’ve tried the solutions posted here, and manual linking works.

  1. Add a react-native.config.js config file in the root of the project with this content:
module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

That will skip autolinking for Realm for iOS.

  1. Add the project RealmReact.xcodeproj from node_modules into your project as a subproject

  2. Be sure to include libRealmReact.a in the Link Binary With Libraries step of your target Build Phases. Important: I’ve spent a lot of time chasing the Cannot read property 'debugHosts' of undefined bug because I was linking to libRealm.a and not libRealmReact.a, I’m sure that may happen to someone else.

I was hyped to use RealmDB for the current project but, I’ve been chasing errors after errors. This is an awesome project and I really hope to see it up without errors soon 😕

@d14na You don’t need to change DB. We’ve got two RN 0.60.5 apps using Realm 2.29.1 live with the Android 64-bit update.

The only issue right now is that it doesn’t support autolinking, but that doesn’t mean you can’t use the module.

Just tell RN it doesn’t support autolinking on ios (Android actually works fine since it works in a different manner) by editing your react-native.config.js like so:

module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

Since you’re upgrading a project I assume your iOS project already has the manually linked RealmReact.xcodeproj? That’ll be sufficient for the iOS side. On the Android side ensure the implementation project(':realm') isn’t in the app/build.gradle and:

include ':realm'
project(':realm').projectDir = new File(rootProject.projectDir, '../node_modules/realm/android')

isn’t in the settings.gradle and you should be good to go on both platforms. Android will autolink, iOS won’t.

same for me

To fix the pod’s use_native_modules!-error, just add a react-native.config.js-file in the root of your project with the following code (exclusive example for realm, but you get the idea):

module.exports = {
  dependencies: {
    realm: {
      platforms: {
        ios: null // disable iOS platform, other platforms will still autolink if provided
      }
    }
  }
};

👉 autolinking info for more details

Disabling autolinking means we have to use good ol’ manual linking, but sadly realm doesn’t provide a guide here and the standard way (as told by the react-native-team) doesn’t work, either.

I followed this guide, but still get the Cannot read property 'debugHosts' of undefined error. It looks like the export of NativeModules in RealmJS is undefined, thus no destruction of debugHosts.

The realm problem I see here is that realm currently doesn’t use CocoaPods for iOS, which prohibits auto linking.

Looking forward for this issue being fixed.

Edit: Fix typo react-native.config.js

I have a PR ready for this https://github.com/realm/realm-js/pull/2586. If some of you have experience writing Podspec files and especially in the context of React Native libraries, it would be really awesome if you spent a few minutes reviewing the change and adding a comment on the PR.

It would also be great if one or more of you wanted to test out the changes:

  1. Clone the PRs branch: git clone --recurse-submodules --single-branch --branch kh/podspec https://github.com/realm/realm-js.git
  2. Pack Realm JS to an archive: npm pack
  3. From your app, install Realm JS from the archive: npm install [path to realm-js]/realm-3.3.0.tgz
  4. Install CocoaPods in your app: pod install (from your ./ios directory).
  5. Build your app and confirm that it’s working … you might need to run react-native unlink realm first.

Apply this

npm install realm@hermes

Work’s for me.

@CaptainQuark could you please edit your comment?

File name must be: react-native.config.js

- react-native-config.js <= Wrong !!!!
+ react-native.config.js

🤦‍♂️ Sure, fixed.

What’s the workaround for this?

run npx react-native link realm then npx jetify ignore the warning, my project is running properly with that