9

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.

himanshu
  • 461
  • 9
  • 21

3 Answers3

3

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(),
  },
};
Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73
0
npx react-native-clean-project
Owais Yosuf
  • 194
  • 1
  • 1
  • 13
0

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