React-native-geolocation-service: Invariant Violation: Native module cannot be null.

Created on 3 Jun 2020  路  11Comments  路  Source: Agontuk/react-native-geolocation-service

I have been using v4.0.0 without problems.
Updating to v5.0.0 is causing the error below on IOS.
Going back to v4.0.0 (no other changes) fixes the issue.

I just updated the version and ran yarn install & pod install.
The bridging header is in the project.
React-Native is at 0.62.2.

Are there any other steps we have to complete to upgrade?

Invariant Violation: Native module cannot be null.

invariant
    browser.js:38:14
constructor
    NativeEventEmitter.js:37:6
<global>
    Geolocation.native.js:3:28
loadModuleImplementation
    require.js:323:4
guardedLoadModule
    require.js:212:11
metroRequire
    require.js:130:6
<unknown>
    index.bundle?platform=ios&dev=true&minify=false:234779:44
loadModuleImplementation
    require.js:323:4
guardedLoadModule
    require.js:212:11
metroRequire
    require.js:130:6

Most helpful comment

Experiencing the same problems as @blumendorf during jest testing

Edit: This is because with v5 we now need to mock the module implementation like:

jest.mock('react-native-geolocation-service', () => ({
  requestAuthorization: jest.fn(),
  getCurrentPosition: jest.fn(),
  ...
}));

All 11 comments

Remove any previous version dependency from your podfile. During pod install, does it report to have found react-native-geolocation-service(5.0.0) ?

It does not report anything about react-native-geolocation-service during pod install.

There also doesn't seem to be anything in Podfile or the Podfile.lock

I also tried deleting the Podfile.lock and Pods folder (and of course the usual cache cleaning, etc) with no success.

Looks like an installation issue. Try removing previous version completely and do a fresh install. If it's available inside node_modules, then pod install should always work.

What exactly do you mean: "Try removing previous version completely and do a fresh install."?

yarn remove react-native-geolocation-service && yarn add react-native-geolocation-service && cd ios && pod install did not fix it. Also rm -rf node_modules && yarn install did not fix it.

On a completely new project fresh install same problem.

Unable to reproduce this, in my case it's installing without any issue.
image

I finally found some time to look into this again today.

It does not work on a clean project for me either.
-> react-native init GeoServiceTest
-> yarn add react-native-geolocation-service
-> cd ios && pod install
-> add import Geolocation from 'react-native-geolocation-service'; in App.js
=> Unhandled JS Exception: Invariant Violation: Native module cannot be null.

In the clean project, it does show the expected output during pod install though (Installing react-native-geolocation-service (5.0.0)) and it does create ios/Pods/Local Podspecs/react-native-geolocation-service.podspec.json during installation. But it still shows the error.

Things I tried to clean my system:

  • rm -rf node_modules ios/Pods ios/build android/app/build
  • yarn cache clean
  • pod cache clean --all
  • rm -rf "${HOME}/Library/Caches/CocoaPods"
  • yarn start --reset-cache

But I still get the same exception.

Any ideas? Anything else I can try to help finding the problem?

Experiencing the same problems as @blumendorf during jest testing

Edit: This is because with v5 we now need to mock the module implementation like:

jest.mock('react-native-geolocation-service', () => ({
  requestAuthorization: jest.fn(),
  getCurrentPosition: jest.fn(),
  ...
}));

Happened to me today on fresh install. latest node && react-native versions. xcode wont launch project

Guys! Make sure to create the swift file with bridging support as mentioned on Readme. Game changer, i promise! 馃

I finally found the issue.

We had this in our react-native.config.js.

dependencies: {
    'react-native-geolocation-service': {
      platforms: {
        ios: null,
      },
    },
  },

According to the commit message to fix some dependency warning.

I have no idea, how I missed that in my previous searches through our project.

Thanks for taking the time to look into it!

Was this page helpful?
0 / 5 - 0 ratings