diff --git a/packages/react-native/src/NativeScriptNativeApi.ts b/packages/react-native/src/NativeScriptNativeApi.ts index 4cb54f02e..e611d7319 100644 --- a/packages/react-native/src/NativeScriptNativeApi.ts +++ b/packages/react-native/src/NativeScriptNativeApi.ts @@ -14,4 +14,17 @@ export interface Spec extends TurboModule { readonly __writeTestMarker: (content: string) => boolean; } -export default TurboModuleRegistry.getEnforcing('NativeScriptNativeApi'); +function loadNativeApi(): Spec { + const nativeApi = TurboModuleRegistry.get('NativeScriptNativeApi'); + if (nativeApi == null) { + throw new Error( + "@nativescript/react-native: the native module 'NativeScriptNativeApi' is not in this app binary. " + + 'The package contains native code, so it cannot run in Expo Go: use a development build ' + + '(npx expo run:ios / npx expo run:android, or EAS Build). ' + + 'If the package was added after the app was built, rebuild the app.', + ); + } + return nativeApi; +} + +export default loadNativeApi();