Question

Ionic/cordova - There is no singleton instance. Make sure you configure Purchases before trying to get the default instance.

  • 12 March 2023
  • 2 replies
  • 227 views

Badge +1

Hello,

I am using the ionic sdks. However for some reason i get the error

“There is no singleton instance. Make sure you configure Purchases before trying to get the default instance.”

I am using the code below and as you can see I am calling Purchases.configureWith before Purchases.getCustomerInfo(). But not sure why I am getting this error?

Can anyone guide as what I am doing wrong?

Also attaching screen of my console

Purchases.setDebugLogsEnabled(true);
if (context.user) {
console.log("before configure");
Purchases.configureWith({
// @ts-ignore
apikey: import.meta.env.VITE_RC_ANDROID_KEY,
appUserID: context.user,
});
console.log("after configure");
try {
console.log("before customerinfo");
const customerInfo = await Purchases.getCustomerInfo();
console.log("after customerinfo");
console.log(customerInfo);
} catch (e) {
console.log(e);
}
}
}

 

console screenshot

 


2 replies

Badge +1

Ok. So I changed Purchases.configureWith() → Purchase.configure() and it is working now.

Thus, this is definitely a bug with the Purchases.configureWith() function in the cordova SDK. Given that .configure() is deprecated, I hope RC team fixes this asap.

Userlevel 5
Badge +9

Hello,

We use configureWith internally on our sample app: https://github.com/RevenueCat/cordova-plugin-purchases/blob/261c4061ca43988fffeaacdf089ced7412c65c36/examples/cordova-sample/MyApp/www/js/index.js#L62-L78 And configure calls configureWith internally: https://github.com/RevenueCat/cordova-plugin-purchases/blob/932ff7d3d3ef00ce27c473306fb888beb91798b3/src/plugin/plugin.ts#L711-L724 I’m struggling to find a reason that would cause configure to work and configureWith not to work. But it’s fine to continue using configure if needed.

Reply