Invariant violation: `new nativeeventemitter()` requires a non-null argument., js engine: hermes

invariant violation: `new NativeEventEmitter()` requires a non-null argument

The error message “invariant violation: `new NativeEventEmitter()` requires a non-null argument” indicates that the NativeEventEmitter constructor is being called with a null or undefined argument, which is not allowed.

The NativeEventEmitter class is a part of the React Native framework and is used for handling events emitted from native code. It requires an instance of the React Native bridge module to be passed as an argument during initialization.

Here is an example to illustrate the correct usage:


import { NativeEventEmitter } from 'react-native';
import MyBridgeModule from './MyBridgeModule';

// Instantiate the bridge module
const myBridgeModule = new MyBridgeModule();

// Pass the bridge module instance to the NativeEventEmitter constructor
const eventEmitter = new NativeEventEmitter(myBridgeModule);
    

In the above example, we have created a custom bridge module called MyBridgeModule to handle native events. We then pass an instance of this module to the NativeEventEmitter constructor.

Make sure that you provide a valid non-null argument to the NativeEventEmitter constructor to avoid this error. Check if the argument you are passing is properly initialized and references a valid bridge module instance.

Related Post

Leave a comment