React-native: EventEmitter in react-native 0.61 is not working as 0.60

Created on 4 Dec 2019  路  3Comments  路  Source: facebook/react-native

When I using EventEmitter in react-native 0.61 I got this error:

Unable to resolve module EventEmitter from Main.js: EventEmitter could not be found within the project.

This is Main.js look like:

import _EventEmitter from 'EventEmitter';
export const EventEmitter = new _EventEmitter();

export const toast = (msg, duration = 4000) => { 
EventEmitter.emit(Constants.EmitCode.Toast, msg, duration) ;
};
Ran Commands Question

Most helpful comment

The magic you describe has been removed: https://github.com/facebook/react-native/issues/24316

To fix the import issue:

import EventEmitter from "react-native/Libraries/vendor/emitter/EventEmitter";

Searching EventEmitter.js in node_modules tells you the path. Same method can be applied on other imports having this type of error.
Example:

import type EmitterSubscription from "EmitterSubscription";

to

import type EmitterSubscription from "react-native/Libraries/vendor/emitter/EmitterSubscription";

All 3 comments


We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

馃憠 Click here if you want to report a reproducible bug or regression in React Native.

The magic you describe has been removed: https://github.com/facebook/react-native/issues/24316

To fix the import issue:

import EventEmitter from "react-native/Libraries/vendor/emitter/EventEmitter";

Searching EventEmitter.js in node_modules tells you the path. Same method can be applied on other imports having this type of error.
Example:

import type EmitterSubscription from "EmitterSubscription";

to

import type EmitterSubscription from "react-native/Libraries/vendor/emitter/EmitterSubscription";

@GunnarAK solution saves the day but still this is an issue

Was this page helpful?
0 / 5 - 0 ratings