Realm-js: node-fetch cause error with latest version react native

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

By trying to load this plugin relam-js on android, I got error below:

E/ReactNativeJNI( 4323): Got JS Exception: Requiring unknown module "node-fetch". (index.android.bundle:2)
E/ReactNativeJNI( 4323): Got JS Stack: [email protected]:2:688
E/ReactNativeJNI( 4323): [email protected]:2:331
E/ReactNativeJNI( 4323): [email protected]:2:245
E/ReactNativeJNI( 4323): [email protected]:2:94
E/ReactNativeJNI( 4323): index.android.bundle:315:1873
E/ReactNativeJNI( 4323): index.android.bundle:315:1857
E/ReactNativeJNI( 4323): [email protected]:2:470
E/ReactNativeJNI( 4323): [email protected]:2:245
E/ReactNativeJNI( 4323): [email protected]:2:94
E/ReactNativeJNI( 4323): [email protected]:322:1321
E/ReactNativeJNI( 4323): index.android.bundle:303:1262
E/ReactNativeJNI( 4323): [email protected]:2:470
E/ReactNativeJNI( 4323): [email protected]:2:245
E/ReactNativeJNI( 4323): [email protected]:2:94
E/ReactNativeJNI( 4323): index.android.bundle:302:43
E/ReactNativeJNI( 4323): [email protected]:2:470
E/ReactNativeJNI( 4323): [email protected]:2:245
E/ReactNativeJNI( 4323): [email protected]:2:94
E/ReactNativeJNI( 4323): index.android.bundle:298:117
E/ReactNativeJNI( 4323): [email protected]:2:470
E/ReactNativeJNI( 4323): [email protected]:2:245
E/ReactNativeJNI( 4323): [email protected]:2:94
E/ReactNativeJNI( 4323): index.android.bundle:297:127
E/ReactNativeJNI( 4323): [email protected]:2:470
E/ReactNativeJNI( 4323): [email protected]:2:245
E/ReactNativeJNI( 4323): [email protected]:2:94
E/ReactNativeJNI( 4323): index.android.bundle:12:38
E/ReactNativeJNI( 4323): [email protected]:2:470
E/ReactNativeJNI( 4323): [email protected]:2:175
E/ReactNativeJNI( 4323): [email protected]:2:94
E/ReactNativeJNI( 4323): global [email protected]:765:9
E/AndroidRuntime( 4323): FATAL EXCEPTION: mqt_js
E/AndroidRuntime( 4323): Process: eu.app.test, PID: 4323
E/AndroidRuntime( 4323): java.lang.RuntimeException: com.facebook.react.devsupport.JSException: Requiring unknown module "node-fetch". (index.android.bundle:2)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.DefaultNativeModuleCallExceptionHandler.handleException(DefaultNativeModuleCallExceptionHandler.java:24)
E/AndroidRuntime( 4323):        at com.facebook.react.devsupport.DisabledDevSupportManager.handleException(DisabledDevSupportManager.java:172)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.CatalystInstanceImpl.onNativeException(CatalystInstanceImpl.java:496)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.CatalystInstanceImpl.access$900(CatalystInstanceImpl.java:41)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.CatalystInstanceImpl$NativeExceptionHandler.handleException(CatalystInstanceImpl.java:512)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:33)
E/AndroidRuntime( 4323):        at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
E/AndroidRuntime( 4323):        at java.lang.Thread.run(Thread.java:818)
E/AndroidRuntime( 4323): Caused by: com.facebook.react.devsupport.JSException: Requiring unknown module "node-fetch". (index.android.bundle:2)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
E/AndroidRuntime( 4323):        at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime( 4323):        at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 4323):        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
E/AndroidRuntime( 4323):        ... 3 more
E/AndroidRuntime( 4323): Caused by: com.facebook.jni.CppException: Requiring unknown module "node-fetch". (index.android.bundle:2)
E/AndroidRuntime( 4323):        ... 7 more

This line is some wrong, really bad idea.
https://github.com/realm/realm-js/blob/4055c9e047b93053eb35402dfc56f2e57e260b92/lib/user-methods.js#L40

Just should be require('node-fetch') for processing and making bundle on platform react native.

Goals

Expected Results

Actual Results


Steps to Reproduce

Code Sample

Version of Realm and Tooling

  • Realm JS SDK Version: 1.13.0
  • Node or React Native: React Native
  • Client OS & Version: Windows 10
  • Which debugger for React Native: ?/None
O-Community Reproduction-Required T-Help

All 16 comments

Can you provide a little project which reproduces the error? Do you also see it if you are using Realm JS 2.0?

I won't use Realm JS 2.0, because during npm install causes error with compiling on windows 10.

I found answer for realm 1.13 like that below:

// bootstrap
import 'whatwg-fetch'
global.fetch = fetch;

// import after bootstrap
import Realm from 'realm';

Thanks for the workaround :-)

Regarding the Realm JS 2.0 + Windows 10 issue, please create an issue for it.

I get the same error, but the workaround didn't work for me.

I can't really provide an example project since it's private code, but this has caused our entire production to shut down.

Edit: As below, happening on a Mac (Windows too though). Same versions too:

Rn: 0.50.1
React : 16.0.0
Realm : 1.13.0

Same here. Not related on Windows, this problem happened also on Mac.

  • Rn: 0.50.1
  • React : 16.0.0
  • Realm : 1.13.0

(Not working Realm 2.0.3 too)

@mriza1815 @darkmantle Thanks for the updates. It looks like we need to do some testing with RN 0.50.x.

FYI: For me it only happens when running a bundled release version - for some reason it works fine when running in debug mode.

Got this error also when i build an iOS app. Only when build configuration is release, debug is working.
RN 0.50.0
React 16.0.0
Realm 2.0.4

Any update on this, or a small (dirty) workaround? We can't deploy a new production build a.t.m.

I tryed the example of @machei but don't know where to put/change the code.

Before import Realm from 'realm'; just type that

import 'whatwg-fetch'
global.fetch = fetch;

Just once type that from file where is intalizing database.

Thanks! I tried it but it didn't work on iOS for me...

Doesn't work on Android either, tried it before commenting.

@kneth can we help you to solve this issue? I don't know realm good enough so can't provide you a pull request or something... But maybe i can't give some specific information of my project so you can reproduce the issue?

As @darkmantle said, this caused our entire production to shut down. It would be nice if this, i think small issue with big consequences, can be fixed.

We are working on upgrading to RN 0.50. I believe it is related to that version, and I hope that we will be able to reproduce the error. See #1483.

For me the issue is fixed... The only thing i did is update RN to 0.50.4, but don't know if that was the fix...

@vdlindenmark Thanks for the update - indeed strange.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmartindivmedianet picture jmartindivmedianet  路  3Comments

kontinuity picture kontinuity  路  3Comments

Chris-Petty picture Chris-Petty  路  3Comments

timanglade picture timanglade  路  3Comments

ashah888 picture ashah888  路  3Comments