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

React-Native - Error: Could not locate the bindings file. Tried: #521

Closed secretyouth closed 7 years ago

secretyouth commented 7 years ago

Hi all,

Hopefully someone can chime in and help me figure this out. I am using React-Native (0.28.0) & Realm (0.14.1) since installing ream my react native tests have been failing due to the following error.

I've literally hit a wall, when I remove the react components that are requiring Realm, they test fine. But with realm the error bellow is returned.

Any help or ideas are much appreciated, as I have tried remove node_modules, npm rebuild & downgraded realm.

Package.json { "name": "reactApp", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "mocha --require react-native-mock/mock.js --compilers js:babel-core/register --recursive test/*.js" }, "dependencies": { "lodash": "^4.13.1", "react": "15.2.0", "react-native": "^0.28.0", "realm": "^0.14.1" }, "devDependencies": { "babel-core": "^6.10.4", "babel-preset-react-native": "^1.9.0", "chai": "^3.5.0", "enzyme": "^2.3.0", "mocha": "^2.5.3", "mockery": "^1.7.0", "react": "^15.2.0", "react-addons-test-utils": "^15.2.0", "react-dom": "^15.2.0", "react-native-mock": "^0.2.4" } }

Error when running npm test

mocha --require react-native-mock/mock.js --compilers js:babel-core/register --recursive test/*.js

/Users/jamiehayman/someApp/reactApp/node_modules/bindings/bindings.js:91 throw err ^

Error: Could not locate the bindings file. Tried: → /Users/jamiehayman/someApp/reactApp/node_modules/realm/build/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/build/Debug/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/build/Release/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/out/Debug/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/Debug/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/out/Release/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/Release/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/build/default/realm.node → /Users/jamiehayman/someApp/reactApp/node_modules/realm/compiled/6.2.2/darwin/x64/realm.node at bindings (/Users/jamiehayman/someApp/reactApp/node_modules/bindings/bindings.js:88:9) at Object. (/Users/jamiehayman/someApp/reactApp/node_modules/realm/lib/index.js:35:41) at Module._compile (module.js:541:32) at Module._extensions..js (module.js:550:10) at Object.require.extensions.(anonymous function) as .js at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object. (realm.js:3:1) at Module._compile (module.js:541:32) at loader (/Users/jamiehayman/someApp/reactApp/node_modules/babel-register/lib/node.js:158:5) at Object.require.extensions.(anonymous function) as .js at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object. (dashboardContainer.js:9:1) at Module._compile (module.js:541:32) at loader (/Users/jamiehayman/someApp/reactApp/node_modules/babel-register/lib/node.js:158:5) at Object.require.extensions.(anonymous function) as .js at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object. (dashboardContainer.test.js:18:1) at Module._compile (module.js:541:32) at loader (/Users/jamiehayman/someApp/reactApp/node_modules/babel-register/lib/node.js:158:5) at Object.require.extensions.(anonymous function) as .js at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.require (module.js:468:17) at require (internal/module.js:20:19) at /Users/jamiehayman/someApp/reactApp/node_modules/mocha/lib/mocha.js:220:27 at Array.forEach (native) at Mocha.loadFiles (/Users/jamiehayman/someApp/reactApp/node_modules/mocha/lib/mocha.js:217:14) at Mocha.run (/Users/jamiehayman/someApp/reactApp/node_modules/mocha/lib/mocha.js:469:10) at Object. (/Users/jamiehayman/someApp/reactApp/node_modules/mocha/bin/_mocha:404:18) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.runMain (module.js:575:10) at run (node.js:348:7) at startup (node.js:140:9) at node.js:463:3 npm ERR! Test failed. See above for more details.

alazier commented 7 years ago

Were you able to figure this out? Seems like we have an incompatibility with the tests or other frameworks you are using. If you can provide a sample project which reproduces the issue we may be able to figure this out more easily.

secretyouth commented 7 years ago

@alazier I ended up removing realm.io at this stage until someone was able to solve this issue. It was still happening when running Mocha Tests.

I was unable to find any information on how to resolve it.

It's a private project at this stage, so I am unable to provide the source for it. It was a very basic project (at the time of posting) and contains only realm, react native and mocha (enzyme, chai, mockery).

Im sure if you set up a basic react-native project with the above package.json you should be able to encounter the same issue.

bppr commented 7 years ago

You have to use the NodeJS backend for building tests that will be run in a node context (which is Mocha, usually)

try executing the scripts/download-core.sh node script, then ./src/node/build-node.sh from withinnode_modules/realm

TGPSKI commented 7 years ago

I"m having the same problem with AVA and Realm for React Native.

OSX 10.11, Node 6.2.2

I tried the download-core.sh & build-node.sh fix, rnpm link, no dice. I also tried upgrading node-gyp as well.

/Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/bindings/bindings.js:91 throw err ^

→ /Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/realm/compiled/6.2.2/darwin/x64/realm.node at bindings (/Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/bindings/bindings.js:88:9) at Object. (/Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/realm/lib/index.js:35:41) at Module._compile (module.js:541:32) at Module._extensions..js (module.js:550:10) at require.extensions.(anonymous function) (/Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/babel-register/lib/node.js:166:7) at extensions.(anonymous function) (/Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/require-precompiled/index.js:16:3) at Object.require.extensions.(anonymous function) as .js at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Module._load (module.js:409:3) at Function.hookedLoader as _load at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object. (/Users/DOBLETBOOF/react-native/dev/ReduxTest/Tests/msgReducer.js:2:15) at Module._compile (module.js:541:32) at extensions.(anonymous function) (/Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/require-precompiled/index.js:13:11) at Object.require.extensions.(anonymous function) as .js at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Module._load (module.js:409:3) at Function.hookedLoader as _load at Module.require (module.js:468:17) at require (internal/module.js:20:19) at Object. (/Users/DOBLETBOOF/react-native/dev/ReduxTest/node_modules/ava/lib/test-worker.js:95:1) at Module._compile (module.js:541:32) at Object.Module._extensions..js (module.js:550:10) at Module.load (module.js:458:32) at tryModuleLoad (module.js:417:12) at Function.Module._load (module.js:409:3) at Module.runMain (module.js:575:10) at run (node.js:348:7) at startup (node.js:140:9) at node.js:463:3

5 passed 1 exception

package.json:

{ "name": "ReduxTest", "version": "0.0.1", "private": true, "scripts": { "start": "node nodemodules/react-native/local-cli/cli.js start", "remotedev": "remotedev --hostname=localhost --port=8000", "test": "ava" }, "dependencies": { "react": "15.2.1", "react-native": "0.29.0", "react-native-router-flux": "^3.31.0", "react-redux": "^4.4.5", "realm": "^0.14.1", "redux": "^3.5.2", "redux-batched-actions": "^0.1.2", "redux-thunk": "^2.1.0", "underscore": "^1.8.3" }, "devDependencies": { "ava": "^0.15.2", "babel-eslint": "^6.1.2", "babel-preset-react-native": "^1.9.0", "deep-freeze-node": "^1.1.2", "enzyme": "^2.4.1", "eslint": "^3.0.1", "eslint-plugin-react": "^5.2.2", "eslint-plugin-react-native": "^1.1.0", "mockery": "^1.7.0", "nyc": "^7.0.0", "react-dom": "^15.2.1", "react-native-mock": "^0.2.4", "remote-redux-devtools": "^0.3.3", "remotedev-server": "^0.1.2" }, "ava": { "babel": "inherit", "files": [ "Tests/*/_.js", "!Tests/Setup.js" ], "require": [ "babel-register", "babel-polyfill", "react-native-mock/mock", "./Tests/Setup" ] } }

TGPSKI commented 7 years ago

Any thoughts? I won't be able to move forward with Realm if I can't get AVA or Jest to work with it.

alazier commented 7 years ago

@TGPSKI we are looking into it to better understand what the issue is.

fealebenpae commented 7 years ago

Hey, I got realm to work under both mocha and AVA, based on @bppr's comment. In your project folder:

  1. cd node_modules/realm
  2. ./scripts/download-core.sh node
  3. Open src/node/binding.gyp and on line 37 replace ../../node_modules/nan with <!(node -e 'require(\"nan\")')
  4. ./src/node/build-node.sh

I only needed step 3 because I've got npm3 and it installs the nan module in a location realm's binding.gyp file doesn't expect.

TGPSKI commented 7 years ago

@fealebenpae changed the above and still getting the following. Maybe I am missing something basic here?

gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] CXX(target) Release/obj.target/realm/node_init.o In file included from ../node_init.cpp:19: In file included from ../node_init.hpp:21: In file included from ../node_string.hpp:21: In file included from ../node_types.hpp:28: ../../js_types.hpp:25:10: fatal error: 'realm/util/to_string.hpp' file not found

include <realm/util/to_string.hpp>

     ^

1 error generated. make: *\ [Release/obj.target/realm/node_init.o] Error 1

fealebenpae commented 7 years ago

@TGPSKI after you execute step 2, is there a core-node folder under node_modules/realm and does it have meaningful contents?

Mine is this ``` core-node ├── LICENSE ├── include │   ├── realm │   │   ├── alloc.hpp │   │   ├── alloc_slab.hpp │   │   ├── array.hpp │   │   ├── array_basic.hpp │   │   ├── array_basic_tpl.hpp │   │   ├── array_binary.hpp │   │   ├── array_blob.hpp │   │   ├── array_blobs_big.hpp │   │   ├── array_integer.hpp │   │   ├── array_string.hpp │   │   ├── array_string_long.hpp │   │   ├── binary_data.hpp │   │   ├── bptree.hpp │   │   ├── column.hpp │   │   ├── column_backlink.hpp │   │   ├── column_binary.hpp │   │   ├── column_fwd.hpp │   │   ├── column_link.hpp │   │   ├── column_linkbase.hpp │   │   ├── column_linklist.hpp │   │   ├── column_mixed.hpp │   │   ├── column_mixed_tpl.hpp │   │   ├── column_string.hpp │   │   ├── column_string_enum.hpp │   │   ├── column_table.hpp │   │   ├── column_timestamp.hpp │   │   ├── column_tpl.hpp │   │   ├── column_type.hpp │   │   ├── column_type_traits.hpp │   │   ├── commit_log.hpp │   │   ├── data_type.hpp │   │   ├── descriptor.hpp │   │   ├── descriptor_fwd.hpp │   │   ├── disable_sync_to_disk.hpp │   │   ├── exceptions.hpp │   │   ├── group.hpp │   │   ├── group_shared.hpp │   │   ├── group_writer.hpp │   │   ├── handover_defs.hpp │   │   ├── history.hpp │   │   ├── impl │   │   │   ├── array_writer.hpp │   │   │   ├── continuous_transactions_history.hpp │   │   │   ├── destroy_guard.hpp │   │   │   ├── input_stream.hpp │   │   │   ├── output_stream.hpp │   │   │   ├── sequential_getter.hpp │   │   │   ├── simulated_failure.hpp │   │   │   └── transact_log.hpp │   │   ├── importer.hpp │   │   ├── index_string.hpp │   │   ├── lang_bind_helper.hpp │   │   ├── link_view.hpp │   │   ├── link_view_fwd.hpp │   │   ├── mixed.hpp │   │   ├── null.hpp │   │   ├── olddatetime.hpp │   │   ├── owned_data.hpp │   │   ├── query.hpp │   │   ├── query_conditions.hpp │   │   ├── query_engine.hpp │   │   ├── query_expression.hpp │   │   ├── realm_nmmintrin.h │   │   ├── replication.hpp │   │   ├── row.hpp │   │   ├── spec.hpp │   │   ├── string_data.hpp │   │   ├── table.hpp │   │   ├── table_accessors.hpp │   │   ├── table_basic.hpp │   │   ├── table_basic_fwd.hpp │   │   ├── table_macros.hpp │   │   ├── table_ref.hpp │   │   ├── table_view.hpp │   │   ├── table_view_basic.hpp │   │   ├── timestamp.hpp │   │   ├── unicode.hpp │   │   ├── util │   │   │   ├── assert.hpp │   │   │   ├── basic_system_errors.hpp │   │   │   ├── bind_ptr.hpp │   │   │   ├── buffer.hpp │   │   │   ├── call_with_tuple.hpp │   │   │   ├── cf_ptr.hpp │   │   │   ├── config.h │   │   │   ├── encrypted_file_mapping.hpp │   │   │   ├── event_loop.hpp │   │   │   ├── features.h │   │   │   ├── file.hpp │   │   │   ├── file_mapper.hpp │   │   │   ├── hex_dump.hpp │   │   │   ├── inspect.hpp │   │   │   ├── interprocess_condvar.hpp │   │   │   ├── interprocess_mutex.hpp │   │   │   ├── logger.hpp │   │   │   ├── memory_stream.hpp │   │   │   ├── meta.hpp │   │   │   ├── misc_errors.hpp │   │   │   ├── miscellaneous.hpp │   │   │   ├── network.hpp │   │   │   ├── optional.hpp │   │   │   ├── priority_queue.hpp │   │   │   ├── safe_int_ops.hpp │   │   │   ├── scope_exit.hpp │   │   │   ├── shared_ptr.hpp │   │   │   ├── string_buffer.hpp │   │   │   ├── terminate.hpp │   │   │   ├── thread.hpp │   │   │   ├── to_string.hpp │   │   │   ├── tuple.hpp │   │   │   ├── type_list.hpp │   │   │   ├── type_traits.hpp │   │   │   ├── uri.hpp │   │   │   └── utf8.hpp │   │   ├── utilities.hpp │   │   ├── version.hpp │   │   └── views.hpp │   └── realm.hpp ├── librealm-node-dbg.a ├── librealm-node.a └── release_notes.txt 4 directories, 120 files ```
TGPSKI commented 7 years ago

@fealebenpae hmm, no. i have core and core-1.1.2 folders but I don't see this tree like you have above.

edit: ./scripts/download-core.sh node vs ./scripts/download-core.sh

fealebenpae commented 7 years ago

@TGPSKI that's just me running tree on the folder to dump its contents. Does yours look anything like that?

fealebenpae commented 7 years ago

Also, it should be core-node and core-node-1.1.2. Did you pass the node argument to download-core.sh?

TGPSKI commented 7 years ago

yes yes yes got it! Just ran some AVA tests with a Realm import, first successful test!

More to come.

Much thanks to @fealebenpae!!

TGPSKI commented 7 years ago

This is super awesome as I already wrote out my Realm helpers and didn't want to revert all that.

Only one basic test so far, but this is really promising! image

alazier commented 7 years ago

Glad you got things working!

m-vdb commented 7 years ago

thanks for this! helped a lot :) I've done a bash version that I used on CircleCI, I put it here just in case: ./bin/build-realm.sh

#!/usr/bin/env bash

set -e

npm install -g node-gyp@3.4.0
cd ./node_modules/realm
# only build realm if not already builded
if [ -d "./node_modules/.bin" ]; then
  echo 'Realm already builded'
else
  mkdir -p ./node_modules/.bin
  ./scripts/download-core.sh node
  sed -i -e "s#../../node_modules/nan#<\!\(node -e 'require\(\\\\\"nan\\\\\"\)'\)#g" src/node/binding.gyp
  ./src/node/build-node.sh
fi

and my circle.yml:

machine:
  node:
    version: 6.0.0

dependencies:
  cache_directories:
    - ~/nvm/versions/node/v6.0.0/lib/node_modules/node-gyp
    - ~/nvm/versions/node/v6.0.0/bin/node-gyp
  post:
    - ./bin/build-realm.sh
bigfish24 commented 7 years ago

All, even though this was resolved, I wanted to post that we are not officially supporting realm-js with Node, although we intend to soon. Instead, if you are interested, please email me at af@realm.io as I would like to learn more on what you would like to see in an official Node release.

shkyang commented 7 years ago

hi, I'm on step 4, ./src/node/build-node.sh, and I received this error:

gyp info using node-gyp@3.4.0 gyp info using node@6.3.1 | darwin | x64 gyp info spawn make gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] CXX(target) Release/obj.target/realm/node_init.o c++: error: unrecognized command line option '-stdlib=libc++' make: *\ [Release/obj.target/realm/node_init.o] Error 1

I think this is using gcc and not clang, in which case my gcc is:

$ gcc --version gcc (MacPorts gcc5 5.4.0_0) 5.4.0

fealebenpae commented 7 years ago

@shkyang: node-gyp is hardcoded to expect Xcode/clang on mac. I think you need to temporarily remove MacPorts from PATH In order to get it to build.

shkyang commented 7 years ago

@fealebenpae: I'm not an expert at the node compilation system, but it seems like the issue here is that clang is not being hardcoded, I was able to get around it like this:

cd ./src/node/build CXX=clang make

Then I did the last two steps of build.sh manually.

cd ../.. mkdir -p build ln -fs "../src/node/build/$CONFIGURATION/realm.node" build/

I wonder if it makes sense to hardcode CXX to clang (on osx) in the .mk file

fealebenpae commented 7 years ago

@shkyang: node-gyp literally expects that CC and CXX will understand the same arguments clang would. Realm's gyp files do not select for a compiler anywhere. I believe exporting the CXX variable to clang++ like you have done is a good solution.

shkyang commented 7 years ago

@fealebenpae. I see what you mean, In this case we can make step 4

CXX=clang ./src/node/build-node.sh

Could also alter build-node.sh to explicitly set CXX on OSX, but I think we've beat on the issue enough.

sharq1 commented 7 years ago

Now the tests pass for me, but they don't quit - Jest prints out summary and hangs.

FYI for me the steps to success were as follows step 1 cd node_modules/realm step 2 ./scripts/download-core.sh node Previous step 3 (Open src/node/binding.gyp and on line 37 replace ../../node_modules/nan with <!(node -e 'require(\"nan\")')) wasn't required for me as the correct value was already there step 3 npm install step 4 ./src/node/build-node.sh

fealebenpae commented 7 years ago

@sharq1: do you by any chance build from the latest source in the repo, instead of using the package from npm? Also, what's your package.json like, especially the jest section? And what version of jest do you use?

sharq1 commented 7 years ago

Sorry, forgot to mention that I'm using realm from git:

"realm": "git+https://git@github.com/realm/realm-js.git",
    "jest": "15.1.1",
    "jest-cli": "15.1.1",
    "jest-react-native": "15.0.0",
  "jest": {
    "preset": "jest-react-native",
    "moduleNameMapper": {
      "\\./datepicker$": "<rootDir>/node_modules/tcomb-form-native/lib/templates/bootstrap/datepicker.ios.js"
    },
    "preprocessorIgnorePatterns": [
      "node_modules/(?!react-native|tcomb-form-native|apsl-react-native-button)"
    ],
    "testRegex": "(/__tests__/.*|\\.(test))\\.js$",
    "collectCoverage": true,
    "verbose": true
  },

When I was using 0.14.3 from npm I was getting Missing Realm constructor - please ensure RealmReact framework is included! error instead of bindings error.

fealebenpae commented 7 years ago

@sharq1: I just tried a new project with your setup with a single test that imports Realm and I can't get jest to hang. Could you prepare a simple app that demonstrates the issue and put it up somewhere so that we can try and debug it?

sharq1 commented 7 years ago

I was able to narrow down the problem - having just the Realm initialized (new Realm({})) causes the terminal to hang. No actual db actions influence this.

alexsotocx commented 7 years ago

Hello, The fix you proposed works but when the test uses Realm Jest never stop the process.

alexsotocx commented 7 years ago

@sharq1 The unique problem that I found with your approach is that I cant compile the applications because there is no android folder... I tried to build it but it was not found :( (they ignore it on https://github.com/realm/realm-js/blob/master/react-native/.npmignore#L1)

johannesschirrmeister commented 7 years ago

@sharq1 @alexsotocx and for everyone else that stumbled upon this issue, fixes it and then experiences a "hanging terminal": I eventually realized that I didn't close my Realm instances (easy to overlook as it's not shown in the Realm React Native docs).

I solved it by running this at the end of the test suite: afterAll(() => { realm.close(); });

alexsotocx commented 7 years ago

@johannesschirrmeister the sad thing is that I can't use on my linux machine for CI. We have to wait.

andrewvmail commented 7 years ago

@sharq1 I was using your script for a while on v0.14.3 tag was working... but the new version doesn't have ./src/node/build-node.sh. Do you know what this step is replaced with now?

Cheers

alazier commented 7 years ago

@andrewvmail you should no longer need to build node as node support has been included into the npm module directly.