Skip to main content
Question

setupPurchases of null on react native / expo


Forum|alt.badge.img+2

I do use Expo but when I try to initialize revenue cat SDK, I got ‘LOG {"error": [TypeError: Cannot read property 'setupPurchases' of null]}’ error.

my code just like that; await Purchases.configure({ apiKey: 'x' })

I’m  using andorid, in real device and emulator.
 

18 replies

Forum|alt.badge.img+8
  • RevenueCat Staff
  • 430 replies
  • September 12, 2023

Forum|alt.badge.img

Hi I have the same problem and I'm using the dev-client.
The error is in the catch of the setup() fonction that is calling the Purchases.configure


Forum|alt.badge.img
onur-anil-mertoglu-271a59 wrote:

I do use Expo but when I try to initialize revenue cat SDK, I got ‘LOG {"error": [TypeError: Cannot read property 'setupPurchases' of null]}’ error.

my code just like that; await Purchases.configure({ apiKey: 'x' })

I’m  using andorid, in real device and emulator.
 

@onur-anil-mertoglu-271a59 have you fix the issue?


Forum|alt.badge.img+4
  • Helper
  • 22 replies
  • February 16, 2024

 I get the same error and I am running a dev build in my device (not expo go)


Forum|alt.badge.img+1
  • New Member
  • 2 replies
  • May 24, 2024

Did anybody found a way to fix this? I also get this error, I have a dev build installed and running. But In my root layout I have React Native Purchases and I get this problem. I have checked that env picks up well the api key, but don’t know why this happens.


Forum|alt.badge.img+1

facing the same issue , api key is fetched correctly but not sure what is causing this error  [TypeError: Cannot read property 'setupPurchases' of null]” 
@ Revenue cart kindly provide your solution on this error


Forum|alt.badge.img+1

Has anyone figured  a work around for this issue , if yes then please do post it here 


Forum|alt.badge.img+1
  • New Member
  • 2 replies
  • May 26, 2024

It’s crazy, I’ve been stuck with this error for more than 2 weeks. Tried everything above, but had no luck.


Forum|alt.badge.img
  • New Member
  • 3 replies
  • August 22, 2024

I have the same issue. I am using the bare workflow and running the development build and still getting this error. Any resolution?


  • New Member
  • 1 reply
  • September 8, 2024

Has anyone found a solution to this?


Forum|alt.badge.img
  • New Member
  • 1 reply
  • October 4, 2024

still no solution to  LOG  [TypeError: Cannot read property 'setupPurchases' of null]?


sharif
RevenueCat Staff
Forum|alt.badge.img+9
  • RevenueCat Staff
  • 513 replies
  • October 4, 2024

Hi all,

Sorry for the delay here - can you share more logs or a screenshot of which line in your code the error happens in? Sounds like the Purchases object isn’t available in the code, so it might be an issue in the how the RevenueCat dependency was added. It might be worth deleting node_modules and npx installing everything again?


i was also facing same error problem is here :  const offerings = await Purchases.getOfferings();

i have even installed it newliy then also its not working


Forum|alt.badge.img+8
  • RevenueCat Staff
  • 430 replies
  • October 11, 2024

Hi @coder @thirdeye-1fe5fb, can both of you try to deleting node_modules and npx and installing it all again? If this does not fix it, then please provide more logs, a stack trace, and the code you are using so we can help look into what you are seeing.


I have the same error


Forum|alt.badge.img+8
  • RevenueCat Staff
  • 430 replies
  • January 6, 2025

Hi ​@kristian-9c00e5, can you try to deleting node_modules and npx and installing it all again? If this does not fix it, then please provide more logs, a stack trace, and the code you are using so we can help look into what you are seeing.


  • New Member
  • 1 reply
  • January 13, 2025

Hi ​@Haley Pace 

I am trying to debug this same issue and looking for help. I have revenuecat fully working for ios but am getting this error on Android: [TypeError: Cannot read property 'setupPurchases' of null]

 

I am on expo managed workflow, running development build. I have deleted my node modules and reinstalled everything. I am hardcoding my revneucat api key so i know it’s present. The main bit of insight that could help me is whether or not this error is related to my revenuecat & Google Play Store setup or it’s just an installation issue. My expectation would be that even if I didn’t have Revenue Cat & Google Play correctly setup the SDK would not crash. 

 

If there’s anything else I can provide, please let me know.

 

Dependencies

"expo": "^52.0.25"
"react-native": "0.76.6"
"react-native-purchases": "^8.5.0"

 

I am running the below code which I took from your example: https://gist.github.com/joshdholtz/3f26a6f06b86d2452d4180182876d824

import React, {useEffect, useState} from 'react';
import {Platform, Text, View} from 'react-native';

import Purchases, {PurchasesOffering} from 'react-native-purchases';

const APIKeys = {
    apple: "your_revenuecat_apple_api_key",
    google: "your_revenuecat_google_api_key",
};

export default function App() {
    const [currentOffering, setCurrentOffering] = useState<PurchasesOffering | null>(null);

    useEffect(() => {
        const setup = async () => {
            if (Platform.OS == "android") {
                await Purchases.configure({apiKey: APIKeys.google});
            } else {
                await Purchases.configure({apiKey: APIKeys.apple});
            }

            const products = await Purchases.getProducts(["test"]);
            const offerings = await Purchases.getOfferings();
            setCurrentOffering(offerings.current);
        };
        Purchases.setDebugLogsEnabled(true);

        setup()
            .catch(console.log);
    }, []);

    if (!currentOffering) {
        return <Text>"Loading..."</Text>;
    } else {
        return (
            <View>
                <Text>Current Offering: {currentOffering.identifier}</Text>
                <Text>Package Count: {currentOffering.availablePackages.length}</Text>
                {
                    currentOffering.availablePackages.map((pkg) => {
                        return <Text>{pkg.product.identifier}</Text>
                    })
                }
            </View>
        );
    }
}

 


Forum|alt.badge.img+8
  • RevenueCat Staff
  • 430 replies
  • January 14, 2025

Hi ​@josh-fd0e17, your code looks good so this looks like the Purchases SDK might have not been imported correctly or there is some issue with the import. I would recommend going through the react-native installation guide and making sure that all steps are followed: https://www.revenuecat.com/docs/reactnative. Let me know if reinstalling the SDK helps, if not then I’m happy to look into this further for you

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings