question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Realm 0.15.3 w/ Jest unable to find module realm.node

See original GitHub issue

Hello, After upgrading to realm 0.15.3, my Jest unit tests stopped working. I have tried both npm and Yarn to install my node modules, but still, it seems that realm.node cannot be found. My app in React Native runs correctly.

It seems similar to this: #713 but I have also tried npm to no avail.

./node_modules/realm/compiled/node-v48_darwin_x64/realm.node' from 'index.js'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:150:17)
      at Object.<anonymous> (node_modules/realm/lib/index.js:77:28)
      at Object.<anonymous> (backend/db/util/db.util.js:5:12)

EDIT: It was working just fine with both yarn and npm in Realm 0.15.0 EDIT2:

After some time debugging, I think I have a good idea why this happens.

I believe the problem lies in the script “install.js”

It seems that in order to install realm.node, the script checks if it is in a react-native environment, by trying to require the react-native package.

The thing is, that when running unit-tests, we are not inside a react-native environment, we are in the node environment even if the react native package is present, since the unit tests are ran in the host machine. Therefore, node-pre-gyp install --fallback-to-build will never run if we are developing in react native.

Bottom line: When trying to have unit tests in react-native, they will always fail, because realm.node will never be installed.

EDIT3: Temporary fix: I added a post install script in the package.json: "postinstall" : "./bin/build-realm.sh"

and inside the folder ./bin, I created a build-realm.sh file with the following contents:

#!/usr/bin/env bash

set -e

npm install -g node-gyp
npm install -g node-pre-gyp

cd ./node_modules/realm/

node-pre-gyp install --fallback-to-build

This will install both node-gyp and node-pre-gyp before executing the build command directly. In my case, I will add the check for pre-existing node-gyp and node-pre-gyp binaries, but you get the idea. It works now.

However, in the case of realm 0.15.3, I believe that no matter what unit testing library one uses, no unit tests will be able to run. I believe that the realm.node file should be built / downloaded immediately after installing, regardless of whether we are developing for react native or not, since unit tests are ran by node, not react native.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
csotirioucommented, Jan 11, 2017

@kristiandupont It works. thank you.

0reactions
fealebenpaecommented, Mar 7, 2017

Yes, this is precisely the issue - Jest runs tests as Node.js code, and Realm is not supported in Node.js on Windows just yet, but it’s something we’re working on at the moment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot find Realm module “(…)\realm.node” in nodejs project
I have installed Realm like the docs say: npm install realm . The module is visible in node_modules folder and package. json ....
Read more >
Jest can't find module - Stack Overflow
First: I assume you didn't include the full content of your application, but it does not look like your app code exports the...
Read more >
realm | Yarn - Package Manager
Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we...
Read more >
Source - GitHub
File format: generates Realms with format v22 (reads and upgrades file format v5 ... Added a failing test case for Node.js scripts failing...
Read more >
[Solved]-Jest & RN & Realm : Error - appsloveworld.com
Coding example for the question Jest & RN & Realm : Error: Cannot find module 'throwOnWrongReactAPI' from 'react-native.js-React Native.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found