facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.14k stars 24.32k forks source link

Unable to parse @ReactMethod annotations from native module #45193

Closed connorpmullins closed 4 months ago

connorpmullins commented 4 months ago

Description

Hello New Arch friends!!

After upgrading to React Native 74/bridgeless from 73 (already was using the new arch), I'm receiving the following issue:

0.74.2: 2024-06-26 13:58:22.563 16714-16799 ReactNativeJS           com.omniafishing.app                 
E  Error: Exception in HostObject::get for prop 'RNIterableAPI': 
com.facebook.react.internal.turbomodule.core.TurboModuleInteropUtils$ParsingException: 
Unable to parse @ReactMethod annotations from native module: RNIterableAPI. 
Details: Module exports two methods to JavaScript with the same name: "setUserId"

The error makes sense, there are two instances of setUserId in the RNIterableAPI package - they're method overloads. I guess it also makes sense javascript doesn't support overloading.

What I don't understand is why this error started popping up now. I ran across this thread where two other people were experiencing the same issue with different packages than me - otherwise I'd continue to assume that I have some sort of configuration or caching issue. That could, of course, still be the case.

Update: It's probably the case. My reproducer demo shows that react native 0.74.2 is in fact working with Iterable. I'm filing this anyway in case anyone else finds their way here in search of help. To everyone supporting react-native, though, feel free to close this. I don't know where to go from here, but I'll report back if I resolve the issue.

Steps to reproduce

  1. Bootstrap a react native project using 0.74.2 and the new arch / bridgeless
  2. Install "@iterable/react-native-sdk": "1.3.19"
  3. Build Android
  4. Try to run Android
  5. It works, what is this kid talking about?

React Native Version

0.74.2

Affected Platforms

Runtime - Android

Areas

Bridgeless - The New Initialization Flow

Output of npx react-native info

System:
  OS: macOS 14.1.2
  CPU: (10) arm64 Apple M1 Pro
  Memory: 66.84 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.3
    path: ~/.nvm/versions/node/v18.20.3/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.nvm/versions/node/v18.20.3/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v18.20.3/bin/npm
  Watchman:
    version: 2023.12.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    Android NDK: 22.1.7171670
IDEs:
  Android Studio: 2023.1 AI-231.9392.1.2311.11330709
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.2
    wanted: 0.74.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: false // not related to the bug, but not sure why this is false

Stacktrace or Logs

E  Error: Exception in HostObject::get for prop 'RNIterableAPI': com.facebook.react.internal.turbomodule.core.TurboModuleInteropUtils$ParsingException: Unable to parse @ReactMethod annotations from native module: RNIterableAPI. Details: Module exports two methods to JavaScript with the same name: "setUserId
2024-06-26 14:50:39.017 11801-11944 Compatibil...geReporter com.omniafishing.app                 D  Compat change id reported: 289878283; UID 10500; state: ENABLED
2024-06-26 14:50:39.027 11801-11944 ReactNativeJS           com.omniafishing.app                 I  Running "main" with {"rootTag":11,"initialProps":{},"fabric":true}
2024-06-26 14:50:39.028 11801-11944 ReactNativeJS           com.omniafishing.app                 E  Invariant Violation: "main" has not been registered. This can happen if:
                                                                                                    * Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
                                                                                                    * A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
2024-06-26 14:50:39.035 11801-12056 TrafficStats            com.omniafishing.app                 D  tagSocket(172) with statsTag=0xffffffff, statsUid=-1
2024-06-26 14:50:39.309 11801-12057 ProfileInstaller        com.omniafishing.app                 D  Installing profile for com.omniafishing.app

Reproducer

https://github.com/connorpmullins/breakIterable

Screenshots and Videos

No response

cortinico commented 4 months ago

The code that fires the error message you mentioned was introduced in 0.73: https://github.com/facebook/react-native/commit/1f7daf988b50005e3c659936c3e598aa3aa310f0

So I'm unsure why you're seeing this only when bumping 0.74 -> 0.73. I have the suspect you were not using bridgeless in 0.73 but we can't really see without the full repro.

Anyway, the error is legit as the Iterable SDK is annotating two methods with the same name (as you said) so they should fix this in their SDK: https://github.com/Iterable/react-native-sdk/blob/e4eb49140a99a66f3d56089a8d2d8c7cc34f13ac/android/src/main/java/com/iterable/reactnative/RNIterableAPIModule.java#L148-L159

connorpmullins commented 4 months ago

@cortinico - seen your work around github, thanks for taking the time to check out my issue and appreciate everything you do for the community!