I created both a react-native library and a react-native project that imports the library through its package.json. A file within the library imports the react-native implementation of EventEmitter:
import EventEmitter from 'EventEmitter';
However, when I run the react-native project, I get the following red-screen error when the packager tries to transform the JS:
Transforming modules 鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枒 98.4% (617/622)...(node:99516) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 757): UnableToResolveError: Unable to resolve module EventEmitter from /Users/<userName>/Documents/<projectDir>/node_modules/<reactNativeLibraryName>/index.js: Module does not exist in the module map or in these directories:
/Users/<userName>/Documents/<projectDir>/node_modules
, /Users/<userName>/Documents/<upOneLevelFromProjectDir>/node_modules
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.
Since the issue seems to also related to the babel transform, here is the project's .babelrc file:
{
"presets": ["react-native"]
}
Create a new react-native library (or even modify an existing one) and add the following line to any file (this is easily demonstrated in index.js):
import EventEmitter from 'EventEmitter';
Run the react-native project that uses that modified library with react-native run-android or react-native run-ios.
The app will build and run, but fail when transforming the Javascript.
It looks like node is looking for EventEmitter in the wrong location, incorrectly assuming that it is in it's own node module, when it is actually within react-native. EventEmitter isn't exported by react-native.js either.
Whatever allows a regular react-native project to resolve the EventEmitter import doesn't work when the project is imported as a react-native library.
I'm currently blocked by a similar Packager issue. Very similar behavior - things build and run OK but in the Simulator get the red screen of death at runtime because something (node? Packager?) is looking in node_modules instead of my repo.
Would very much appreciate any insight on this.
I am seeing the exact same behavior with my library as well.
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
@hramos
I am getting the below error. I have tried out the steps mentioned in the error console. But no luck.
"react": "16.0.0-alpha.12",
"react-native": "0.48.3",

The development server returned response error code: 500
URL: http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false
Body:
{"from":"/Users/abc/development/react_native/node_modules/react-native-root-siblings/lib/AppRegistryInjection.js","to":"react-native/Libraries/EventEmitter/EventEmitter","message":"Unable to resolve module react-native/Libraries/EventEmitter/EventEmitter from /Users/abc/development/react_native/node_modules/react-native-root-siblings/lib/AppRegistryInjection.js: Module does not exist in the module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches: watchman watch-del-all.\n 2. Delete the node_modules folder: rm -rf node_modules && npm install.\n 3. Reset packager cache: rm -fr $TMPDIR/react-* or npm start -- --reset-cache.","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]}
processBundleResult
BundleDownloader.java:170
access$100
BundleDownloader.java:39
onResponse
BundleDownloader.java:139
execute
RealCall.java:135
run
NamedRunnable.java:32
runWorker
ThreadPoolExecutor.java:1113
run
ThreadPoolExecutor.java:588
run
Thread.java:818
Most helpful comment
@hramos
I am getting the below error. I have tried out the steps mentioned in the error console. But no luck.
The development server returned response error code: 500
URL: http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false
Body:
{"from":"/Users/abc/development/react_native/node_modules/react-native-root-siblings/lib/AppRegistryInjection.js","to":"react-native/Libraries/EventEmitter/EventEmitter","message":"Unable to resolve module
react-native/Libraries/EventEmitter/EventEmitterfrom/Users/abc/development/react_native/node_modules/react-native-root-siblings/lib/AppRegistryInjection.js: Module does not exist in the module map\n\nThis might be related to https://github.com/facebook/react-native/issues/4968\nTo resolve try the following:\n 1. Clear watchman watches:watchman watch-del-all.\n 2. Delete thenode_modulesfolder:rm -rf node_modules && npm install.\n 3. Reset packager cache:rm -fr $TMPDIR/react-*ornpm start -- --reset-cache.","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]}processBundleResult
BundleDownloader.java:170
access$100
BundleDownloader.java:39
onResponse
BundleDownloader.java:139
execute
RealCall.java:135
run
NamedRunnable.java:32
runWorker
ThreadPoolExecutor.java:1113
run
ThreadPoolExecutor.java:588
run
Thread.java:818