Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 291 forks source link

Invariant Violation: `new NativeEventEmitter()` requires a non-null argument. #346

Open nachoSource opened 2 years ago

nachoSource commented 2 years ago

Environment

System: OS: macOS 12.4 CPU: (8) x64 Apple M1 Memory: 24.48 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.13.1 - /usr/local/bin/node Yarn: Not Found npm: 8.1.2 - /usr/local/bin/npm Watchman: 2022.03.21.00 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7935034 Xcode: 13.4/13F17a - /usr/bin/xcodebuild Languages: Java: 18.0.1.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.2 => 0.68.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Platforms

This is only happening in iOS (I am working with the xCode simulator). In Android devices it works fine.

Versions

Please add the used versions/branches

Description

Please provide a clear and concise description of what the bug is. Include screenshots if needed.

Reproducible Demo

Provide a detailed list of steps that reproduce the issue.

  1. Install a new app following the [RN doc](Invariant Violation: new NativeEventEmitter() requires a non-null argument.) and the instructions required in this library's readme files.
  2. Run cd ios && pod install
  3. Run either npm run ios or use the xCode interface (the error is the same)

Expected Results

The app runs properly as it does in Android devices

Here is the complete error log:

image
nachoSource commented 2 years ago

Here I attach some screenshots taken from my simulator. I've also read that the second error usually disappears when the first one is solved, but I show it just in case. image

image
nachoSource commented 2 years ago

Apparently, this import has some kind of issue 🤔 https://user-images.githubusercontent.com/69126302/170710377-4c39ab83-09c5-4e07-b7b1-f93d7b11f2c6.mov

dgasch512 commented 2 years ago

I was getting this until I ran cd ios/ && pod install after installing the package. Could be a pod issue?

Agontuk commented 2 years ago

pod install is required and it's already described in the setup docs.

k-saparia commented 2 years ago

This issue still persists.... on development is all good. However, when I run yarn test, I get this error!! Current Version is 5.3.0

mwmcode commented 2 years ago

Happens when I run appium (e2e tests). It fails to load the app bundle (when in dev mode, loads release bundles fine) onto iOS emulator. After some debugging, it turned out that that error is thrown whenever some packages are present:

The (hacky) workaround I have is to dynamically/conditionally import() such packages when NOT running in E2E mode (env var)

export let requestUserPermission = ( _user: User) => ({});

if (!Env.IS_E2E_MODE) {
  (async function loadFirebaseMessaging() {
    const { default: messaging } = await import(
      '@react-native-firebase/messaging'
    );
    requestUserPermission = async (user: User) => {
      const authStatus = await messaging().requestPermission();
      // ....etc
    }
   })();
}
erickcrus commented 1 year ago

same issue

divyanshGarg96 commented 1 year ago

I am facing the same issue. Has someone found the solution to this ?

kimcccheung commented 1 year ago

I face the same issue. Any solutions?

nassim-yagoub commented 1 year ago

I faced the same issue on IOS and solved it by adding this line to my podfile: pod 'react-native-geolocation-service', path: '../node_modules/react-native-geolocation-service'

According to the setup docs it should not be necessary for RN 0.60 or higher but it solved the issue for me with RN 0.65.3.

However I still had the issue when running tests, I solved it by mocking the package, I only needed PositionError so I created a file __mocks__/react-native-geolocation-service.ts in which I put this enum:

export default {};

export enum PositionError {
  PERMISSION_DENIED = 1,
  POSITION_UNAVAILABLE = 2,
  TIMEOUT = 3,
  PLAY_SERVICE_NOT_AVAILABLE = 4,
  SETTINGS_NOT_SATISFIED = 5,
  INTERNAL_ERROR = -1,
}

You can probably mock everything else you need from this package

lmasneri commented 1 year ago

Same issue there

gomezmark commented 1 year ago

any updates? have you guys solved this issue? thank you

inaieforster commented 1 year ago

same issue :(

anishsundarjee commented 1 year ago

Adding this fixed it for me.

MAKARD commented 1 year ago

RN 0.70 same here

AliBaig-xD commented 1 year ago

In my case I forgot to run pod install in my app. Other way is to link the library manually in your podfile

DongDongDongDong commented 1 year ago

I also encountered the same problem, but it was prompted that the module I couldn't find is the NativeKeyboardObserver. I am using version 0.68.

<null Invariant Violation: new NativeEventEmitter() requires a non-null argument.>

Do you guys have a solution

danieledisons commented 8 months ago

I also have the same issue. Any solution??

RobertMaksymow commented 1 week ago

Adding this into jest.setup.js helped:

jest.mock('@react-native-firebase/messaging', () => ({
  __esModule: true,
  default: jest.fn(() => ({})),
}))