RevenueCat / RevenueCat/react-native-purchases
Purchases.syncPurchases error: "There is no singleton instance. Make sure you configure Purchases before trying to get the default instance."
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 117
- Avg merge
- 14h 40m
- Merged PRs (30d)
- 40
Description
- [✅ ] I have updated Purchases SDK to the latest version
- [✅] I have read the Contribution Guidelines
- [✅] I have searched the Community
- [✅] I have read docs.revenuecat.com
- [✅] I have searched for existing Github issues
Describe the bug
Purchases.syncPurchases() Error:
WARN Possible Unhandled Promise Rejection (id: 0):
Error: There is no singleton instance. Make sure you configure Purchases before trying to get the default instance. More info here: https://errors.rev.cat/configuring-sdk
- Environment
- Platform: iOS and Android
- SDK version: 6.6.5
- OS version:
- Xcode/Android Studio version:
- React Native version: 0.72.4
- SDK installation (CocoaPods + version or manual):
- How widespread is the issue. Percentage of devices affected. 100%
- Debug logs that reproduce the issue
- Steps to reproduce, with a description of expected vs. actual behavior
index.js:
import Purchases from 'react-native-purchases';
Purchases.setLogLevel(Purchases.LOG_LEVEL.DEBUG);
Purchases.configure({apiKey: xxxxxxxxxxxxxxxx});
App.tsx
const storage = new MMKV();
const App = () => {
useEffect(() => {
const init = async () => {
try {
if (!storage.getBoolean(MMKVKeys.HAS_SYNCED_PURCHASES)) {
const configured = await Purchases.isConfigured();
console.log('revenue cat is configured:', configured); // this console.log shows "revenue cat is configured: true"
if (configured) {
await Purchases.syncPurchases();
storage.set(MMKVKeys.HAS_SYNCED_PURCHASES, true);
console.log('mmkv stored:', storage.getBoolean(MMKVKeys.HAS_SYNCED_PURCHASES)); // this console.log shows "mmkv stored: true"
console.log('revenue cat purchases synced') // this console.log is printed successfully;
};
};
} catch (error) {
console.log('caught error', error)
}
};
init();
},[])
};
export default App;
interestingly syncPurchases resolves the promise successfully so the error is not caught by the try/catch block. an unhandled promise warning is thrown AFTER syncPurchases() has supposedly already completed.
- Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)
LOG Platform: ios 16.6.1 Mode: debug
LOG Running "SAMPLE" with {"rootTag":1,"initialProps":{}}
LOG revenue cat is configured: true
LOG mmkv stored: true
LOG revenue cat purchases synced
WARN Possible Unhandled Promise Rejection (id: 0):
Error: There is no singleton instance. Make sure you configure Purchases before trying to get the default instance. More info here: https://errors.rev.cat/configuring-sdk
Error: There is no singleton instance. Make sure you configure Purchases before trying to get the default instance. More info here: https://errors.rev.cat/configuring-sdk
at call (native)
at UninitializedPurchasesError (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:137882:30)
at anonymous (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:137668:132)
at call (native)
at step (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:136259:23)
at anonymous (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:136208:20)
at fulfilled (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:136167:30)
at tryCallOne (/Users/distiller/react-native/packages/react-native/sdks/hermes/build_iphoneos/lib/InternalBytecode/InternalBytecode.js:53:16)
at anonymous (/Users/distiller/react-native/packages/react-native/sdks/hermes/build_iphoneos/lib/InternalBytecode/InternalBytecode.js:139:27)
at apply (native)
at anonymous (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:34672:26)
at _callTimer (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:34551:17)
at _callReactNativeMicrotasksPass (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:34596:17)
at callReactNativeMicrotasks (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:34802:44)
at __callReactNativeMicrotasks (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:3505:46)
at anonymous (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:3279:45)
at __guard (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:3478:15)
at flushedQueue (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:3278:21)
at invokeCallbackAndReturnFlushedQueue (http://192.168.0.100:8081/index.bundle//&platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=com.sample:3272:33)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the setup in index.js and the useEffect flow in App.tsx, then reproduce the reported behavior on iOS and Android with the stated SDK and React Native versions. Done means determining why an unhandled singleton error appears after syncPurchases resolves and validating the behavior with an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100