fix: don't crash at import time when native modules are unavailable - #462
Open
AhmedAlAmawi wants to merge 2 commits into
Open
fix: don't crash at import time when native modules are unavailable#462AhmedAlAmawi wants to merge 2 commits into
AhmedAlAmawi wants to merge 2 commits into
Conversation
When the native module isn't linked (Expo Go, Jest, web bundles, a prebuild before pods are installed), NativeModules.IntercomEventEmitter is undefined and the module-scope constant reads in index.tsx (e.g. IntercomEventEmitter.UNREAD_COUNT_CHANGE_NOTIFICATION) throw at import time, crashing the app on boot. Fall back to an empty object so failure is deferred to actual API calls instead of the import.
AhmedAlAmawi
force-pushed
the
fix/guard-missing-native-modules
branch
from
August 2, 2026 16:54
1d0704e to
1c9a7c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When the Intercom native module isn't available — Expo Go, Jest, a web bundle, or a prebuild before pods are installed —
NativeModules.IntercomEventEmitterisundefined. Sincesrc/index.tsxreads constants off it at module scope (IntercomEventEmitter.UNREAD_COUNT_CHANGE_NOTIFICATION,WINDOW_DID_SHOW_NOTIFICATION, …), merely importing the package throws:and crashes the app at boot, before any Intercom API is called.
This PR falls back to an empty object (
?? {}) for bothIntercomModuleandIntercomEventEmitter, deferring the failure from import time to the first actual API call — where callers can handle it. Behavior is completely unchanged whenever the native module exists.We've been running this exact change as a local patch in our production React Native (Expo) app — it's what lets the package coexist with environments where the native side isn't present.
Changes
src/nativeModules.ts:?? {}fallback on both exports__tests__/nativeModules.test.ts: covers both paths — exports fall back to empty objects when the native module is missing (import doesn't throw), and pass through untouched when it's registeredVerification
yarn typescript✅yarn lint✅yarn jest __tests__/nativeModules.test.ts✅ (2/2 passing)Notes
dev, but that branch's last commit is from 2022 and all recently merged PRs targetmain, so this targetsmain. Happy to retarget ifdevis still the intended base.