NativeModules are empty

See original GitHub issue

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® Core™ 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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6

github_iconTop GitHub Comments

2reactions
stale[bot]commented, Oct 12, 2020

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.

1reaction
mojtabasjicommented, Jul 11, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

NativeModules empty object · Issue #26813 - GitHub
I tried to recreate the Native Modules for Android guide on React Native's documentation, NativeModules was an empty object.
Read more >
React Native NativeModules Empty Object - Stack Overflow
It's for a React Native app. No matter what I try, the module returns undefined. NativeModules always appears to be an empty object....
Read more >
getting empty object in react native NativeModules - Reddit
Hey, I'm learning about native modules and following documentation. But I'm getting empty object when I console `NativeModules` and null ...
Read more >
Importing NativeModules gives me an empty object even ...
[Solved]-Importing NativeModules gives me an empty object even though my native module is properly created and registered-React Native. Search. score:2.
Read more >
Native Modules
To expose a method to JavaScript a Java method must be annotated using @ReactMethod . The return type of bridge methods is always...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found