Realm-js: iOS: Custom step download_realm.js fails -> Build error "realm/util/assert.hpp" not found

Created on 18 Oct 2017  路  14Comments  路  Source: realm/realm-js

Goals

Just installing/building realm for use in a React Native iOS app.

Expected Results

As a pre-build step, the RealmJS target executes node ../scripts/download-realm.js ios --sync, which should populate the vendor directory with some code and build dependencies.

Actual Results

The script fails, apparently because the wrong version of lzma-native is being run/built:

PhaseScriptExecution Download\ Core <snip>

Extracting realm-sync-cocoa-2.0.2.tar.xz => <myproject>l/node_modules/realm/vendor/realm-ios
{ Error: Cannot find module '<myproject>/node_modules/lzma-native/binding-v3.0.1-node-v51-darwin-x64/lzma_native.node'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at <myproject>/node_modules/lzma-native/index.js:13:14
    at Object.<anonymous> (<myproject>/node_modules/lzma-native/index.js:595:3)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12) code: 'MODULE_NOT_FOUND' }

Then on the compilation step:

CompileC <snip>/RealmJS.build/Objects-normal/arm64/index_set.o object-store/src/index_set.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler

<myproject>/node_modules/realm/src/object-store/src/index_set.cpp:21:10: fatal error: 'realm/util/assert.hpp' file not found
#include <realm/util/assert.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Build failed    18/10/2017, 12:10

lzma-native is present (v3.0.1) but doesn't contain the particular binding node wants:

ll node_modules/lzma-native
total 144
-rw-r--r--    1 rob  staff   4.4K  4 Jul 21:56 CHANGELOG.md
-rw-r--r--    1 rob  staff   1.1K 27 Apr  2016 LICENSE
-rw-r--r--    1 rob  staff    23K 24 Mar  2017 README.md
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 bin
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v1.5.3-node-v53-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v2.0.0-node-v53-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v2.0.1-node-v55-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v2.0.2-node-v55-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v2.0.3-node-v56-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v2.0.4-electron-v1.7-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v2.0.4-node-v48-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v2.0.4-node-v56-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v3.0.0-electron-v1.7-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v3.0.0-node-v56-linux-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:01 binding-v3.0.1-node-v48-darwin-x64
drwxr-xr-x    3 rob  staff   102B 17 Oct 23:00 binding-v3.0.1-node-v56-linux-x64
-rw-r--r--    1 rob  staff   3.1K 24 Mar  2017 binding.gyp
-rwxr-xr-x    1 rob  staff   253B 12 Jan  2016 cflags.sh
drwxr-xr-x   12 rob  staff   408B 17 Oct 23:00 deps
-rw-r--r--    1 rob  staff    14K  4 Jul 21:55 index.js
-rwxr-xr-x    1 rob  staff    52B 28 Sep  2015 liblzma-build.sh
-rwxr-xr-x    1 rob  staff   443B 12 Jan  2016 liblzma-config.sh
drwxr-xr-x  111 rob  staff   3.7K 18 Oct 11:50 node_modules
-rw-r--r--    1 rob  staff   1.5K  4 Jul 21:55 package.json
drwxr-xr-x   11 rob  staff   374B 17 Oct 23:00 src

If I run the script manually (outside xcode) it succeeds:

node ../scripts/download-realm.js ios --sync
Extracting realm-sync-cocoa-2.0.2.tar.xz => <myproject>/node_modules/realm/vendor/realm-ios

(../vendor/ream-ios is now populated)
However the build still fails unless I also remove the pre-build step from xcode, because a failed execution appears to wipe the realm-ios directory.

Whenever yarn reinstalls realm, I need to repeat this process. I've tried totally cleaning everything out - node_modules, yarn cache clean, Clean build in xcode, removing Derived data, to no avail. For some reason I always end up with a mismatched lzma-native build.

Steps to Reproduce

yarn add [email protected]
react-native link realm
...build in xcode

Code Sample

Version of Realm and Tooling

  • Realm JS SDK Version: 2.0.0
  • Node or React Native: React Native 0.49, Node 6.3.1, yarn 0.27.5
  • Client OS & Version: macOS Sierra building for iOS 11
  • Which debugger for React Native: N/A (build issue)

Most helpful comment

After some debugging I found Xcode uses node from /usr/local/bin/ directory.

$ node --version
v7.6.0
$ /usr/local/bin/node --version
v6.2.2

So syncing both node versions to 7.6.0 fixed the issue and the download script didn't fail anymore.

All 14 comments

Ahh, well filling out the issue template led me to the solution!

I have nvm installed, and XCode was using node 6.3 while yarn was installing/building lzma-native under node 7.5, so naturally node-gyp wasn't creating the bindings on the shell that XCode's version of node needed.

Syncing my node versions up fixed the problem.

@rh389 I have the same mismatch I assume. How can I update my xcode node version?

Xcode will just use whichever version is available to /bin/sh. Assuming you normally use a different shell (I use zsh via iTerm2) they could be mismatched.

Fire up your usual shell, run /bin/sh from within that to dip into the system shell, and run node --version and which node from there to see what Xcode sees. Use nvm from whichever shell is out of date to bring it in line with the other shell (in my case zsh was using an older version than sh).

nvm alias default 7.5 (for example) will fix the default for the shell to 7.5.

both versions on xterm e "regular term" are 7.10.1

but i keep the similar error of

Resolved requirements: { SYNC_SERVER_FOLDER: 'sync', SYNC_ARCHIVE: 'realm-sync-cocoa-2.1.0.tar.xz', SYNC_ARCHIVE_ROOT: 'core' } No lockfile found at the target, proceeding. Extracting realm-sync-cocoa-2.1.0.tar.xz => /Users/magic/PROJECTS/REACT_NATIVE/happysalus_police/node_modules/realm/vendor/realm-ios { Error: Cannot find module '/Users/magic/PROJECTS/REACT_NATIVE/happysalus_police/node_modules/lzma-native/binding-v3.0.1-node-v57-darwin-x64/lzma_native.node' at Function.Module._resolveFilename (module.js:513:15) at Function.Module._load (module.js:463:25) at Module.require (module.js:556:17) at require (internal/module.js:11:18) at /Users/magic/PROJECTS/REACT_NATIVE/happysalus_police/node_modules/lzma-native/index.js:13:14 at Object.<anonymous> (/Users/magic/PROJECTS/REACT_NATIVE/happysalus_police/node_modules/lzma-native/index.js:595:3) at Module._compile (module.js:612:30) at Object.Module._extensions..js (module.js:623:10) at Module.load (module.js:531:32) at tryModuleLoad (module.js:494:12) code: 'MODULE_NOT_FOUND' } Command /bin/sh failed with exit code 1

It looks like xcode's finding node 8 somewhere on your system (it's looking for a v57 binary). What's /usr/local/bin/node --version?

hello @rh389, thanks to open this issue.
I have the same problem. I'm using node v7.5.0 (installed by nvm) and zsh terminal.
I can't check with /usr/local/node --version

I have run nvm alias default 7.5

$ nvm list
->       v7.5.0
         v8.9.0
default -> 7.5 (-> v7.5.0)
node -> stable (-> v8.9.0) (default)
stable -> 8.9 (-> v8.9.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> N/A)
lts/argon -> v4.8.6 (-> N/A)
lts/boron -> v6.12.0 (-> N/A)
lts/carbon -> v8.9.1 (-> N/A)

I still get the same error, I have checked node_modules/lzma-native but binding-v3.0.1-node-v57-darwin-x64 doesn't exist. can you explain the steps you do to face this error?
thanks

Hey I finally fixed my issue, the problem was that I always use bash and had some configs in bash that my shell couldn't find so it just stopped working. Fixing that part and remembering that if you use cocoa pods you should open the project via the .xcworkspace instead of the .xcodeproj did it for me.

@gino8080 Did you find a solution? I'm facing same error. Running node 8.0.0 on both sh & bash.

After some debugging I found Xcode uses node from /usr/local/bin/ directory.

$ node --version
v7.6.0
$ /usr/local/bin/node --version
v6.2.2

So syncing both node versions to 7.6.0 fixed the issue and the download script didn't fail anymore.

What is the full path of ../scripts/download-realm.js? I don't think I have it... wondering if this script failing could be why I keep getting the Missing Realm constructor error

This is the build phase for RealmJS:

[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
  . "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
  . "$(brew --prefix nvm)/nvm.sh"
fi

if [[ "$(command -v nvm)" ]]; then
 nvm install 7.10.0
fi

 node ../scripts/download-realm.js ios --sync

how is that node version determined? I'm using node 8 for both bin/node and usr/local/bin/node, but xcode is trying to use this other random version...

Nevermind, swapping out that version doesn't do anything (for me)!

@kevboh did you get this resolved. I am facing the same issue. Terminal shows node version 8.9.1 but build phase RealmJS showing 7.10.0

@Daishygoyal we ended up "solving" with this workaround: https://github.com/realm/realm-js/issues/1576#issuecomment-356847411

Was this page helpful?
0 / 5 - 0 ratings