From 1073a4bbc0fd2cff0784aa71545a8444d924ca00 Mon Sep 17 00:00:00 2001 From: kristiandupont Date: Thu, 16 Feb 2017 10:53:30 +0100 Subject: [PATCH] Update index.js to report missing react-native link --- lib/index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/index.js b/lib/index.js index 353abe3b..6bb739a9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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);