react-native-geolocation-service icon indicating copy to clipboard operation
react-native-geolocation-service copied to clipboard

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

Open nachoSource opened this issue 3 years ago • 20 comments

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

  • iOS: 15.0
  • react-native-geolocation-service: master & ios-rewrite
  • react-native: 0.68.2

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 avatar May 26 '22 14:05 nachoSource

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 avatar May 26 '22 14:05 nachoSource

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

nachoSource avatar May 27 '22 13:05 nachoSource

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

dgasch512 avatar Jun 16 '22 21:06 dgasch512

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

Agontuk avatar Jun 17 '22 15:06 Agontuk

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

k-saparia avatar Aug 23 '22 16:08 k-saparia

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:

  • react-native-device-info
  • @react-native-firebase/messaging

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
    }
   })();
}

mwmcode avatar Aug 26 '22 13:08 mwmcode

same issue

erickcrus avatar Oct 20 '22 00:10 erickcrus

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

divyanshGarg96 avatar Nov 04 '22 11:11 divyanshGarg96

I face the same issue. Any solutions?

kimcccheung avatar Nov 16 '22 09:11 kimcccheung

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

nassim-yagoub avatar Nov 16 '22 10:11 nassim-yagoub

Same issue there

lmasneri avatar Nov 16 '22 13:11 lmasneri

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

gomezmark avatar Nov 25 '22 09:11 gomezmark

same issue :(

inaieforster avatar Nov 30 '22 14:11 inaieforster

Adding this fixed it for me.

anishsundarjee avatar Dec 14 '22 10:12 anishsundarjee

RN 0.70 same here

MAKARD avatar Feb 22 '23 12:02 MAKARD

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

AliBaig-xD avatar Feb 28 '23 21:02 AliBaig-xD

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

DongDongDongDong avatar Jun 19 '23 13:06 DongDongDongDong

I also have the same issue. Any solution??

danieledisons avatar Feb 02 '24 23:02 danieledisons