himanshu
himanshu

Reputation: 501

@react-native-community/netinfo: NativeModule.RNCNetInfo is null after install latest version

I have updated react native version from 0.57 to 0.59.1. After successful updated it throws error in react native info, so i installed @react-native-community/netinfo and removed Netinfo from react-native.

I have run below commands to install latest version of netinfo:

npm install --save @react-native-community/netinfo

react-native link @react-native-community/netinfo

cd ios && pod install

After successful linking when run my project i got error @react-native-community/netinfo: NativeModule.RNCNetInfo is null...

I also tried with version 3 of netinfo but same error occurred.

Version:

@react-native-community/netinfo: ^5.3.2

react: ^16.8.3

react-native": ^0.59.1

Please help me if anyone have solution for this.

Thanks.

Upvotes: 12

Views: 8613

Answers (3)

user9541096
user9541096

Reputation:

npx react-native-clean-project

It will remove all unnecessary files which are not required by the project but are attached with your project during npm install. These type of errors are mostly treated by cleaning of your project by using: npx react-native-clean-project in React Native.

For doing same thing in android studio, we use :

Build > Clean Project

Hope it helps and solve your issue. Happy to help :)

Upvotes: 0

Eric Carlotto
Eric Carlotto

Reputation: 1

If you are using mac to emule your device.

try:

macOS Platform:

Autolinking is not yet available on macOS. See the Manual linking steps for macOS below.

Manually link the library on macOS Open your project .xcodeproj on xcode.

Right click on the Libraries folder and select Add files to "yourProjectName".

Add RNCNetInfo.xcodeproj (located at node_modules/@react-native-community/react-native-netinfo/macos) to your project Libraries.

Go to Build Phases -> Link Binary with Libraries and add: libRNCNetInfo-macOS.a.

https://www.npmjs.com/package/@react-native-community/netinfo#manual-linking-macos

Upvotes: 0

Akshay Vijay Jain
Akshay Vijay Jain

Reputation: 15935

If you are getting this error while running jest test. Add following file to be used as a mock source
add a mock for the NetInfo bridge module and you need not update the Jest config...
file location ==> __mocks__/@react-native-community/netinfo.js

export default {
  getCurrentConnectivity: jest.fn(),
  isConnectionMetered: jest.fn(),
  addListener: jest.fn(),
  removeListeners: jest.fn(),
  isConnected: {
    fetch: () => {
      return Promise.resolve(true);
    },
    addEventListener: jest.fn(),
    removeEventListener: jest.fn(),
  },
};

Upvotes: 4

Related Questions