undefined is not a function in eventEmitter.addListener$argument_1(react-native-purchases/dist/purchases)
Describe the bug The React Native Purchases SDK throws a "TypeError: undefined is not a function" error when initializing on React Native 0.79.4. The error occurs in the event emitter setup where eventEmitter.addListener is called on an undefined object.
- Environment a. Platform: iOS and Android b. SDK version: 8.11.5 c. OS version: iOS 17+ / Android 13+ d. Xcode/Android Studio version: Xcode 15.2 / Android Studio Giraffe e. React Native version: 0.79.4 f. SDK installation (CocoaPods + version or manual): npm (Expo SDK 53 managed workflow) g. How widespread is the issue. Percentage of devices affected: 100%
- occurs on all devices during app initialization
- https://docs.revenuecat.com/docs/debugging that reproduce the issue TypeError: undefined is not a function mechanism: onerror handled: false
/node_modules/react-native-purchases/dist/purchases.js in eventEmitter.addListener$argument_1 at line 72:21
eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.addListener("Purchases-LogHandlerEvent", function (_a) { var logLevel = _a.logLevel, message = _a.message; var logLevelEnum = purchases_typescript_internal_1.LOG_LEVEL[logLevel]; customLogHandler(logLevelEnum, message); });
- Steps to reproduce, with a description of expected vs. actual behavior - Install mailto:[email protected] in a React Native 0.79.4 project - Initialize Purchases SDK with Purchases.configure({ apiKey, appUserID }) - Expected: SDK initializes successfully - Actual: App crashes with "undefined is not a function" error during event listener setup
- Other information - The issue appears to be related to NativeEventEmitter compatibility with React Native 0.79.x - The error occurs at line 56 in purchases.js where new react_native_1.NativeEventEmitter(RNPurchases) is called - The eventEmitter variable becomes undefined, causing subsequent addListener calls to fail - This is likely a breaking change in React Native 0.79's event emitter API
👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!
Ahhhh, it looks like there was a breaking change in this version of RN with imports 😬 👇 We will take a look!
https://github.com/facebook/react-native/releases/tag/v0.79.0
@joshdholtz Could You Fix it and release a patch maybe its causing crashes for the production app Thanks !
Also facing this issue. Although, this error is only thrown when there is no internet connection. Works fine for me otherwise.
@joshdholtz Any Update on this our crash rates are going up very fast due to this issue on play console !!
This is causing crashes for us. Any updates on this
Please assist with this. Our app crashes alot because of that.
I had a similar issue — the error looked almost identical to the one described in the bug report.
My solution was to add a customLogHandler, for example:
Purchases.setLogHandler((logLevel, message) => {
console.log(`RevenueCat Log - ${LOG_LEVEL[logLevel]}: ${message}`)
})
Maybe this will help you too.