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

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: i@index.android.bundle:2:688
E/ReactNativeJNI( 4323): n@index.android.bundle:2:331
E/ReactNativeJNI( 4323): t@index.android.bundle:2:245
E/ReactNativeJNI( 4323): e@index.android.bundle:2:94
E/ReactNativeJNI( 4323): index.android.bundle:315:1873
E/ReactNativeJNI( 4323): index.android.bundle:315:1857
E/ReactNativeJNI( 4323): n@index.android.bundle:2:470
E/ReactNativeJNI( 4323): t@index.android.bundle:2:245
E/ReactNativeJNI( 4323): e@index.android.bundle:2:94
E/ReactNativeJNI( 4323): exports@index.android.bundle:322:1321
E/ReactNativeJNI( 4323): index.android.bundle:303:1262
E/ReactNativeJNI( 4323): n@index.android.bundle:2:470
E/ReactNativeJNI( 4323): t@index.android.bundle:2:245
E/ReactNativeJNI( 4323): e@index.android.bundle:2:94
E/ReactNativeJNI( 4323): index.android.bundle:302:43
E/ReactNativeJNI( 4323): n@index.android.bundle:2:470
E/ReactNativeJNI( 4323): t@index.android.bundle:2:245
E/ReactNativeJNI( 4323): e@index.android.bundle:2:94
E/ReactNativeJNI( 4323): index.android.bundle:298:117
E/ReactNativeJNI( 4323): n@index.android.bundle:2:470
E/ReactNativeJNI( 4323): t@index.android.bundle:2:245
E/ReactNativeJNI( 4323): e@index.android.bundle:2:94
E/ReactNativeJNI( 4323): index.android.bundle:297:127
E/ReactNativeJNI( 4323): n@index.android.bundle:2:470
E/ReactNativeJNI( 4323): t@index.android.bundle:2:245
E/ReactNativeJNI( 4323): e@index.android.bundle:2:94
E/ReactNativeJNI( 4323): index.android.bundle:12:38
E/ReactNativeJNI( 4323): n@index.android.bundle:2:470
E/ReactNativeJNI( 4323): t@index.android.bundle:2:175
E/ReactNativeJNI( 4323): e@index.android.bundle:2:94
E/ReactNativeJNI( 4323): global code@index.android.bundle: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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

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.

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

Thanks for the workaround 😃

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