react-native icon indicating copy to clipboard operation
react-native copied to clipboard

NativeModules are empty

Open Sebulec opened this issue 4 years ago • 11 comments

Description

When creating new native library for application, when library is attached to the react native mobile application in iOS, the NativeModules are empty ({})

React Native version:

System: OS: macOS 10.15.5 CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz Memory: 30.54 MB / 8.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 12.14.1 - /usr/local/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.14.2 - /usr/local/bin/npm SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 IDEs: Android Studio: 3.6 AI-192.7142.36.36.6308749 Xcode: 10.3/10G8 - /usr/bin/xcodebuild npmPackages: react: 16.11.0 => 16.11.0 react-native: 0.62.2 => 0.62.2 npmGlobalPackages: create-react-native-app: 3.4.0 react-native-create-library: 3.1.2 react-native: 0.61.4

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Create new RN application using create-react-native-app my-project
  2. Create new native library using react-native-create-library -—platforms ios,android my-library
  3. Configure XCode .xcworkspace project, link React library to the project, to let project see React binaries.
  4. In my-project app add
import { Button, NativeModules } from 'react-native';
const App: () => React$Node = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <Button title="Press" onPress={() => onPress()}></Button>
      </SafeAreaView>
    </>
  );

  function onPress() {
    console.log(NativeModules);
  }
};

Expected Results

It doesn't matter if it's XCode 11 or XCode 10, the NativeModules is empty. When printing NativeModules.MyLibrary it's null.

Sebulec avatar Jun 26 '20 12:06 Sebulec

Does the behavior vary with remote JS debugging being enabled and disabled?

chrisbobbe avatar Jul 08 '20 22:07 chrisbobbe

@chrisbobbe Thanks for response, when JS is enabled, I can see some libraries but there is no MyLibrary. Zrzut ekranu 2020-07-10 o 07 13 43

Sebulec avatar Jul 10 '20 05:07 Sebulec

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] avatar Oct 12 '20 00:10 stale[bot]

i have same issue nativeModule returns null for both android and ios

mojtabasji avatar Jul 11 '22 14:07 mojtabasji

我也是,请问你解决了 吗?

123jiacheng123 avatar Jul 25 '22 09:07 123jiacheng123

I too.

rb185264 avatar Dec 01 '22 13:12 rb185264

Anybody working on this issue or has anyone found a fix? I am currently experiencing the issue too.

expo: "~48.0.4" react: "18.2.0" react-native: "0.71.3"

Gradle version is 7.5.1. XCode version is 1.74.3 (Universal)

Can't share the project as it is private but I was working from this tutorial..

macro6461 avatar Mar 03 '23 14:03 macro6461

Yes, I am getting the same issue on the same version of react-native 0.71.3. I can see a duplicate issue here. I followed the same guide @macro6461

silvabacc avatar Mar 07 '23 21:03 silvabacc

Same happening on version 0.71.13

lumairink avatar Oct 11 '23 19:10 lumairink

Happening to me i created a native component following the guide from react native docs the native component returns null on react-native version 0.73.1. i found old discussion about this issue Native Modules #96 but no proper resolution yet.

Gowthamr221 avatar Dec 30 '23 16:12 Gowthamr221

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Jun 28 '24 05:06 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jul 05 '24 05:07 github-actions[bot]