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) ;
};
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
Most helpful comment
The magic you describe has been removed: https://github.com/facebook/react-native/issues/24316
To fix the import issue:
Searching
EventEmitter.jsin node_modules tells you the path. Same method can be applied on other imports having this type of error.Example:
to