Search code examples
react-nativesubclasseventemitter

Extending EventEmitter class of react-native fails with `Super expression must either be null or a function`


I have followed the examples for ES6 here.

https://ourcodeworld.com/articles/read/445/how-to-use-event-emitters-with-es5-and-es6-in-node-js-easily

My code:

import {EventEmitter} from 'react-native';

class A extends EventEmitter {
  constructor() {
    super();
  }
}

export const a = new A();

When I run this in my React Native app (RN 0.68), I get the following message, and a red error screen in the app:

ERROR  TypeError: Super expression must either be null or a function

Solution

  • Importing the EventEmitter from the right place solved my problem

    import {EventEmitter} from 'events';