Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method

I cannot resolve the issue. When application loads react native throw warnings.

WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `addListener` method.
WARN  `new NativeEventEmitter()` was called with a non-null argument without the required `removeListeners` method.
like image 233
Muhammad Tahir Avatar asked Oct 12 '21 10:10

Muhammad Tahir


4 Answers

This is likely due to the newest version of react-native. A lot of libraries still haven't released a new version to handle these warnings (or errors in some case). Examples include https://github.com/react-navigation/react-navigation/issues/9882 and https://github.com/APSL/react-native-keyboard-aware-scroll-view/pull/501. If it bothers you, you can hide the warning for now (source):

import { LogBox } from 'react-native';
LogBox.ignoreLogs(['new NativeEventEmitter']); // Ignore log notification by message
LogBox.ignoreAllLogs(); //Ignore all log notifications
like image 80
anya Avatar answered Oct 27 '22 01:10

anya


I just add two function to main java module:

    // Required for rn built in EventEmitter Calls.
    @ReactMethod
    public void addListener(String eventName) {

    }

    @ReactMethod
    public void removeListeners(Integer count) {

    }

Example: for fix warning in react-native-fs add functions to android/src/main/java/com/rnfs/RNFSManager.java file.

For Kotlin use this code:

@ReactMethod
fun addListener(type: String?) {
    // Keep: Required for RN built in Event Emitter Calls.
}

@ReactMethod
fun removeListeners(type: Int?) {
    // Keep: Required for RN built in Event Emitter Calls.
}
like image 27
Sajad Speed Avatar answered Oct 27 '22 00:10

Sajad Speed


same error.

change

const eventEmitter = new NativeEventEmitter(NativeModules.CustomModule);

to

const eventEmitter = new NativeEventEmitter();

works

like image 4
Frank Fan Avatar answered Oct 27 '22 02:10

Frank Fan


1- update your react-native-reanimated library to "react-native-reanimated": "2.0.0"

2- You should update the babel.config.json file and add react-native-reanimated/plugin to plugins

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [
    "react-native-reanimated/plugin",
  ],
};

This will fix your issue

like image 1
Jamal Basha Avatar answered Oct 27 '22 02:10

Jamal Basha