Update index.js to report missing react-native link

This commit is contained in:
kristiandupont 2017-02-16 10:53:30 +01:00
parent 33c2f7cefc
commit 1073a4bbc0

View File

@ -23,7 +23,6 @@ function nodeRequire(module) {
return require(module);
}
function getContext() {
// If process is an object, we're probably running in Node or Electron
// From: http://stackoverflow.com/a/24279593/1417293
@ -36,14 +35,16 @@ function getContext() {
return 'nodejs';
}
// If we've already injected the Realm class, we are probably
// running in a jscore environment, either directly or via React Native
if (typeof Realm !== 'undefined') {
if (typeof navigator !== 'undefined' &&
navigator.product === 'ReactNative') { // eslint-disable-line no-undef
return 'reactnative';
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') { // eslint-disable-line no-undef
if (typeof Realm === 'undefined'){
throw new Error('Missing Realm constructor. Did you run "react-native link realm"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting');
}
return 'reactnative';
}
// If we're not running in React Native but we already injected the Realm class,
// we are probably running in a pure jscore environment
if (typeof Realm !== 'undefined') {
return 'jscore';
}
@ -89,7 +90,7 @@ switch(getContext()) {
}
if (!realmConstructor) {
throw new Error('Missing Realm constructor. Did you run "react-native link realm"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting');
throw Error("Error trying to establish execution context");
}
require('./extensions')(realmConstructor);