Realm-js: rnpm realm fails

Created on 31 Mar 2016  ·  30Comments  ·  Source: realm/realm-js

I am trying to use realm within my react native project.
I first installed realm: npm install --save realm
Then linking to realm

$ rnpm link realm
rnpm-link info Linking realm android dependency
$

Nothing happens after that message. I tried unlinking and it says its not linked yet.

$ rnpm unlink realm
rnpm-link info Unlinking realm android dependency
rnpm-link info Android module realm is not linked yet
rnpm-link info Unlinking realm ios dependency
rnpm-link info iOS module realm is not linked yet

T-Bug

Most helpful comment

@breezykermo here was the workaround for the previous issue. Does this resolve your issue?

WARNING: Due to an issue with rnpm https://github.com/rnpm/rnpm/issues/119, if your project contains the word “Example” or “Test” then you must first explicitly tell rnpm where to find your Xcode project by adding the following to your package.json file:

"rnpm": {
  "ios": {
    "project": "ios/<project-name>.xcodeproj"
  }
}

All 30 comments

I met the same problem.

What versions of react-native are you guys using? I just verified everything works with a new project using v0.22.2. Perhaps we have an issue with older versions?

I just updated rnpm from 1.5.2 to 1.5.4 and now I can reproduce the issue. Will try to come up with a fix asap.

Until we have a fix, you can link Realm manually to your project:

  • Drag the RealmReact.xcodeproj from node_modules/realm/react-native-ios to the Libraries folder in your ios project
  • Add libRealmReact.a to Link Binary with Libraries phase in Build Phases in you applications settings

After that you should be able to use Realm normally.

Looks like other projects are having this issue as well: https://github.com/rnpm/rnpm/issues/127

I think it is rnpm problem 🙂

It was an rnpm-plugin-link problem, and we're really sorry for it.
Now it's fixed (update rnpm-plugin-link to version 1.6.7 or higher to fix the issue).

Awesome! I am blown away with quick response. Thanks.

I am sorry I didn't provide complete information. Yes, it's latest version of rnpm that has the issue.

I will update the rnpm plugin link or link manually to see if that works. Thanks again.

I followed these steps:

Drag the RealmReact.xcodeproj from node_modules/realm/react-native-ios to the Libraries
Add libRealmReact.a to Link Binary with Libraries phase in Build Phases in you applications settings

I now get a different error in XCode (7.2.1). The files libc++.tbd and libz.tbd is in the Bolts "Link Binary with libraries" but I still get this error. It works fine if I remove realm libraries. Are you aware of it?

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't open file: /Applications/Xcode.app/Contents/.../SDKs/iPhoneSimulator9.2.sdk/usr/lib/libc++.tbd (No such file or directory)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't open file: /Applications/Xcode.app/Contents/.../SDKs/iPhoneSimulator9.2.sdk/usr/lib/libz.tbd (No such file or directory)

I fixed the issue. Here is the solution.

In Bolts project Targets:
Remove the libz.tbd file from the Libraries and Frameworks area.
Edit your build settings for Other Linker Flags add "-lz"

In my project, I have libc++.tbd, libz.tbd along with libRealmReact.a. I get the duplicate symbol error.

duplicate symbol _OBJC_METACLASS_$_GCDWebServerErrorResponse in:
/Users/...ios/Build/Products/Debug-iphonesimulator/libBolts.a(GCDWebServerErrorResponse.o)
/Users/...ios/Build/Products/Debug-iphonesimulator/libRealmReact.a(GCDWebServerErrorResponse.o)

@nranganathan1 I was afraid we'd run into these kinds of conflicts when switching from a framework to a static library. I'm on vacation this week, but I will resolve these conflicts when I return. For now, you can modify the RealmReact target by removing the libGCDWebServers.a from Other Librarian Flags.

I'm encountering the same issue. When I manually link the library, like @nranganathan1 outlines above, I get 186 errors, of the following nature:

Undefined symbols for architecture x86_64:
  "std::logic_error::what() const", referenced from:
      vtable for realm::util::BadOptionalAccess in libRealmReact.a(table_view-iphonesimulator-bitcode.o)
      vtable for realm::util::BadOptionalAccess in libRealmReact.a(query-iphonesimulator-bitcode.o)
      vtable for realm::Results::OutOfBoundsIndexException in libRealmReact.a(results.o)
      vtable for realm::util::BadOptionalAccess in libRealmReact.a(query_builder.o)
  "std::runtime_error::what() const", referenced from:
      vtable for RJSException in libRealmReact.a(js_init.o)
      vtable for realm::RealmFileException in libRealmReact.a(realm_coordinator.o)
      vtable for realm::MismatchedConfigException in libRealmReact.a(realm_coordinator.o)
      vtable for RJSException in libRealmReact.a(rpc.o)
      vtable for RJSException in libRealmReact.a(js_list.o)
      vtable for RJSException in libRealmReact.a(js_util.o)
      vtable for RJSException in libRealmReact.a(js_object.o)
      ...
  "std::__1::error_code::message() const", referenced from:
      realm::_impl::RealmCoordinator::get_realm(realm::Realm::Config) in libRealmReact.a(realm_coordinator.o)
      realm::util::make_dir(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRealmReact.a(file-iphonesimulator-bitcode.o)
      realm::util::remove_dir(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libRealmReact.a(file-iphonesimulator-bitcode.o)
      realm::util::File::open_internal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, realm::util::File::AccessMode, realm::util::File::CreateMode, int, bool*) in libRealmReact.a(file-iphonesimulator-bitcode.o)
      realm::util::File::read(char*, unsigned long) in libRealmReact.a(file-iphonesimulator-bitcode.o)
      realm::util::File::write(char const*, unsigned long) in libRealmReact.a(file-iphonesimulator-bitcode.o)
      realm::util::File::resize(long long) in libRealmReact.a(file-iphonesimulator-bitcode.o)
      ...
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
      realm_js::RPCServer::perform_request(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator>&) in libRealmReact.a(rpc.o)
      realm_js::RPCServer::deserialize_json_value(nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator>) in libRealmReact.a(rpc.o)
      ListGetProperty(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSString*, OpaqueJSValue const**) in libRealmReact.a(js_list.o)
      ListSetProperty(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSString*, OpaqueJSValue const*, OpaqueJSValue const**) in libRealmReact.a(js_list.o)
      ResultsGetProperty(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSString*, OpaqueJSValue const**) in libRealmReact.a(js_results.o)
      ResultsSetProperty(OpaqueJSContext const*, OpaqueJSValue*, OpaqueJSString*, OpaqueJSValue const*, OpaqueJSValue const**) in libRealmReact.a(js_results.o)
      RJSValidatedNotificationName(OpaqueJSContext const*, OpaqueJSValue const*) in libRealmReact.a(js_realm.o)
      ...
  "std::__1::error_category::equivalent(std::__1::error_code const&, int) const", referenced from:
      vtable for (anonymous namespace)::system_category in libRealmReact.a(basic_system_errors-iphonesimulator-bitcode.o)
  "std::__1::error_category::equivalent(int, std::__1::error_condition const&) const", referenced from:
      vtable for (anonymous namespace)::system_category in libRealmReact.a(basic_system_errors-iphonesimulator-bitcode.o)
  "std::__1::error_category::default_error_condition(int) const", referenced from:
      vtable for (anonymous namespace)::system_category in libRealmReact.a(basic_system_errors-iphonesimulator-bitcode.o)
  "std::__1::__shared_weak_count::__get_deleter(std::type_info const&) const", referenced from:
      vtable for std::__1::__shared_ptr_emplace<realm::_impl::RealmCoordinator, std::__1::allocator<realm::_impl::RealmCoordinator> > in libRealmReact.a(realm_coordinator.o)
      vtable for std::__1::__shared_ptr_emplace<realm::Realm, std::__1::allocator<realm::Realm> > in libRealmReact.a(realm_coordinator.o)
      vtable for std::__1::__shared_ptr_emplace<realm::_impl::AsyncQuery, std::__1::allocator<realm::_impl::AsyncQuery> > in libRealmReact.a(results.o)
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      void std::__1::vector<nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator>, std::__1::allocator<nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator> > >::__push_back_slow_path<nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator> >(nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator>&&) in libRealmReact.a(RealmReact.o)
      std::__1::vector<nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator>, std::__1::allocator<nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, long long, double, std::__1::allocator> > >::allocate(unsigned long) in libRealmReact.a(RealmReact.o)
      void std::__1::vector<realm::_impl::WeakRealmNotifier, std::__1::allocator<realm::_impl::WeakRealmNotifier> >::__emplace_back_slow_path<std::__1::shared_ptr<realm::Realm>&, bool&>(std::__1::shared_ptr<realm::Realm>&&&, bool&&&) in libRealmReact.a(realm_coordinator.o)
      std::__1::vector<realm::ObjectSchema, std::__1::allocator<realm::ObjectSchema> >::allocate(unsigned long) in libRealmReact.a(realm_coordinator.o)
      std::__1::vector<realm::Property, std::__1::allocator<realm::Property> >::allocate(unsigned long) in libRealmReact.a(realm_coordinator.o)
      void std::__1::vector<std::__1::weak_ptr<realm::Realm>, std::__1::allocator<std::__1::weak_ptr<realm::Realm> > >::__push_back_slow_path<std::__1::weak_ptr<realm::Realm> >(std::__1::weak_ptr<realm::Realm>&&) in libRealmReact.a(realm_coordinator.o)
      void std::__1::vector<std::__1::weak_ptr<realm::_impl::RealmCoordinator>, std::__1::allocator<std::__1::weak_ptr<realm::_impl::RealmCoordinator> > >::__push_back_slow_path<std::__1::weak_ptr<realm::_impl::RealmCoordinator> const&>(std::__1::weak_ptr<realm::_impl::RealmCoordinator> const&&&) in libRealmReact.a(realm_coordinator.o)

I'm not sure if this is the same error. The library links fine in android, both through rnpm and by manually adding the library.

@breezykermo what is the name of your project? We previously had issues with project names that had the word Test in them but we thought this had been fixed by the latest version of rnpm. Unfortunately it looks like we are still requiring the older version in our package.json so this still may be causing problems.

@breezykermo here was the workaround for the previous issue. Does this resolve your issue?

WARNING: Due to an issue with rnpm https://github.com/rnpm/rnpm/issues/119, if your project contains the word “Example” or “Test” then you must first explicitly tell rnpm where to find your Xcode project by adding the following to your package.json file:

"rnpm": {
  "ios": {
    "project": "ios/<project-name>.xcodeproj"
  }
}

Unfortunately it doesn't seem to change anything, @alazier. The project name doesn't have 'Test' or 'Example' in it, and explicitly declaring the rnpm path still gives the same incomplete logs:

rnpm-link info Linking realm android dependency 
rnpm-link info Android module realm is already linked 
rnpm-link info Linking realm ios dependency 

Curiously, now when I try to run rnpm unlink realm, I get the following:

/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1819
            for(var i in secondObj)
                    ^

RangeError: Maximum call stack size exceeded
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1819:21)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)
    at merge_obj (/Users/lachlankermode/.nvm/versions/node/v4.2.6/lib/node_modules/rnpm/node_modules/rnpm-plugin-link/node_modules/xcode/lib/parser/pbxproj.js:1820:26)

I'm on the most recent rnpm (just redownloaded to double check).

Looks really weird. I don't actually think that it caused by rnpm. But just to be super sure: cc @grabbou

https://github.com/rnpm/rnpm/issues/119 is already fixed, so you don't need to do anything as long as you have folder under ios.

Latest version links realm fine for me, at least on iOS - that's where I've tried. Would be cool if we could upgrade :)

The issue you are getting might be due to something non-standard in xcodeproj that causes underlying node-xcode library to crash. If you don't mind, please send me pbxproj that is inside your xcodeproj (does not have any sensitive data) to my email so I can double check.

Is the issue we are having boiling down to these libz++ etc. not linked?

My issue is now fixed. Here is what happened.

When I ran "rnpm realm", it added "libRealmReact.a" to the Bolts and when I added manually the "libRealmReact.a" to my project, I got the duplicate symbol error.

Solution: I removed the library from Bolts and all the needed library is added to my project "Linked Frameworks and Libraries". See image below.

screen shot 2016-04-08 at 10 03 46 am

Also I added -lz and $(inherited) in Build Settings -> Other Linker Flags.

These changes resolved my issues.

I just tried on iOS with a freshly initialized project and libc++.tbd & libz.tbd wasn't linked.

npm install --save realm
rnpm link realm

Got this on build :

Undefined symbols for architecture armv7:
  "std::logic_error::what() const", referenced from:
      vtable for realm::util::BadOptionalAccess in libRealmReact.a(table_view-iphoneos-bitcode.o)
      vtable for realm::util::BadOptionalAccess in libRealmReact.a(query-iphoneos-bitcode.o)
      vtable for realm::Results::OutOfBoundsIndexException in libRealmReact.a(results.o)
      vtable for realm::util::BadOptionalAccess in libRealmReact.a(query_builder.o)
[...]

Manually add : libz.tbd and libc++.tbd from _Link Binary With Libraries_

It works !

npm ls -g rnpm
/Users/ncharpentier/.nvm/versions/node/v5.9.0/lib
└── [email protected]

cc @grabbou @Kureev @alazier

Yes, we do not link that yet. That's my goal for this weekend :) thanks for giving rnpm a go!

@alazier It should be included into getting started documentation until @grabbou and @Kureev continue their good work.

You shouldn't have to manually add the libraries to the project - this should be done automatically when the rnpm-postlink.js script is run. For some reason this script is not getting run properly.

For the time being if you run the following from your project directory the libraries get added automatically:

node node_modules/realm/scripts/rnpm-postlink.js

@grabbou any idea why this script isn't working properly when run from rnpm? Or is it not getting run at all?

I created a PR (rnpm/rnpm-plugin-link#65) to resolve the issue of postlink not being called. It includes a new test to help ensure these commands are called when expected.

@charpeni, works perfectly thanks, in terms of manually hooking the library up. Just tried rnpm linking and unlinking with realm in a new project, and everything seems to be in working order, minus that postlink issue. Thank you for all your great work!

Thanks guys and really sorry for the bug! It's now been updated (1.6.2 rnpm)

Thanks for fixing it. You guys rock!

I'm running into the same issue, fixed by adding libz.tbd and libc++.tbd manually as per @charpeni's suggestion.

Tools:

  • rnpm 1.6.2
  • node 4.3.1
  • npm 2.14.12
  • react-native-cli 0.2.0
  • react-native 0.24.1

cc @grabbou @Kureev @alazier

Running node node_modules/realm/scripts/rnpm-postlink.js does nothing. Logging stuff gives that config.ios is null, so the if block never runs.

Ah... package.son of realm 0.11.1 list a dependency of rnpm 1.5.2.

That's the problem. The rnpm-postlink.js requests var config = rnpm.getProjectConfig() from that sub module.

Was this page helpful?
0 / 5 - 0 ratings