Skip to content

Commit

Permalink
Merge c14a8f1 into 254b02c
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen authored Mar 2, 2024
2 parents 254b02c + c14a8f1 commit a7b36de
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* None

### Enhancements
* None
* Added detection and better instructions when imported from the Expo Go app. ([#6523](https://github.com/realm/realm-js/pull/6523))

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
Expand Down
41 changes: 41 additions & 0 deletions packages/realm/src/platform/react-native/expo-go-detection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2024 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////

import { Platform } from "react-native";

export function isExpoGo() {
try {
// @ts-expect-error - This depends on unstable Expo implementation details
return typeof expo === "object" && expo.modules?.ExponentConstants?.executionEnvironment === "storeClient";
} catch {
return false;
}
}

export class RealmInExpoGoError extends Error {
constructor() {
const runCommand = `npx expo run:${Platform.OS}`;
super(
`'realm' was imported from the Expo Go app, but unfortunately Expo Go doesn't contain the native module for the 'realm' package - consider using an Expo development build instead:\n\nnpm install expo-dev-client\n${runCommand}\n\nRead more: https://docs.expo.dev/develop/development-builds/introduction/`,
);
}
}

if (isExpoGo()) {
throw new RealmInExpoGoError();
}
1 change: 1 addition & 0 deletions packages/realm/src/platform/react-native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//
////////////////////////////////////////////////////////////////////////////

import "./expo-go-detection";
import "./binding";
import "./fs";
import "./device-info";
Expand Down

0 comments on commit a7b36de

Please sign in to comment.