react-native-purchases icon indicating copy to clipboard operation
react-native-purchases copied to clipboard

undefined is not a function in eventEmitter.addListener$argument_1(react-native-purchases/dist/purchases)

Open on-mokshit opened this issue 7 months ago • 9 comments

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.

  1. 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
  1. 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); });

  1. 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
  2. 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

on-mokshit avatar Jun 21 '25 18:06 on-mokshit

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

RCGitBot avatar Jun 21 '25 18:06 RCGitBot

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

Image

joshdholtz avatar Jul 03 '25 16:07 joshdholtz

@joshdholtz Could You Fix it and release a patch maybe its causing crashes for the production app Thanks !

on-mokshit avatar Jul 03 '25 19:07 on-mokshit

Also facing this issue. Although, this error is only thrown when there is no internet connection. Works fine for me otherwise.

mibaloch avatar Jul 06 '25 11:07 mibaloch

@joshdholtz Any Update on this our crash rates are going up very fast due to this issue on play console !!

on-mokshit avatar Jul 20 '25 07:07 on-mokshit

This is causing crashes for us. Any updates on this

oncourse-subs avatar Aug 01 '25 18:08 oncourse-subs

Please assist with this. Our app crashes alot because of that.

theidg avatar Oct 17 '25 21:10 theidg

I had a similar issue — the error looked almost identical to the one described in the bug report.

Image

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.

JurajBilansky avatar Oct 23 '25 19:10 JurajBilansky