0

I am using monorepo created using Yarn Workspaces which has a react-native project (mobile folder) and a common folder which contains the common files to be shared across projects. Here the mobile project is dependent on common files.

The Android app runs fine in debug mode. When I run in release mode, it crashes as soon as it opens. I am getting the below error.

E/ReactNativeJS: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
      This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

--------- beginning of crash
2022-06-07 23:48:09.865 5772-5799/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.myapp.mobile, PID: 5772
com.facebook.react.common.JavascriptException: TypeError: t is not a function. (In 't(u)', 't' is undefined), stack:
<unknown>@460:2846
map@-1
<unknown>@460:2825
N@457:7733
<unknown>@455:172
h@2:1585
<unknown>@453:262
h@2:1585
<unknown>@403:148
h@2:1585
<unknown>@6:57
h@2:1585
d@2:958
global code@529:3

    at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
    at android.os.Looper.loop(Looper.java:223)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
    at java.lang.Thread.run(Thread.java:923)

While researching about this, I came across this suggestion and tired it. Found out that the functions which I import from common is causing this error. It is present in node_modules but not sure whether it is getting packed into the bundle or not.

Mobile's package.json: enter image description here

Any Suggestions?

Joshua
  • 1,167
  • 1
  • 14
  • 32

1 Answers1

0

I think you should change the import flow the way you are importing the package in your package.json file.

See the example below of the react-native-image-crop-picker importing the library in their example code.

enter image description here

And the library code is in the same parent directory.

enter image description here

Vicky Ahuja
  • 906
  • 3
  • 9
  • I have checked it. The entry file name in native and AppRegistry import is fine. I have imported the *common* folder as `@myapp/common` to use its functions. So it seems like that common package is not bundled in the release apk or it is not referenced correctly but works fine in debug mode. Because if I comment that import from `@myapp/common`, the release apk works fine. Any idea why it is happening? – Joshua Jun 12 '22 at 17:17
  • Can you share the piece of code about you talking with the project structure? – Vicky Ahuja Jun 12 '22 at 18:06
  • I have added the screenshot of Mobile's package.json in the question. – Joshua Jun 13 '22 at 04:18
  • @Joshua, You defined the version number there in package.json file. There should be the relative path to the package folder. – Vicky Ahuja Jun 14 '22 at 17:11
  • It is referenced using that package's name. The *common* folder's name is `myapp/common` which is present in *common*'s package.json – Joshua Jun 18 '22 at 19:27
  • I think you should try the above answer, As I got your point with the @imports but for now I couldn't find anything, I have seen once this type of import for the whole project. – Vicky Ahuja Jun 19 '22 at 06:21
  • I have tried your suggestion. But still I am getting the same error. – Joshua Jun 21 '22 at 18:24