Why is Contacts
null in React Native CLI when using react-native-contacts@8
?
I'm building a mobile app using React Native CLI (not Expo), and I'm trying to use the react-native-contacts
library (version 8.0.4). I've followed all the instructions for Android (added permissions, requested them at runtime), but calling:
Contacts.getAll()
throws this error:
TypeError: Cannot read property 'getAll' of null
When I inspected the source code in node_modules/react-native-contacts/index.ts
, I noticed that the module resolution depends on this line:
const isTurboModuleEnabled = global.__turboModuleProxy != null;
In my case, global.__turboModuleProxy
is defined, but TurboModuleRegistry.get('Contacts')
returns null
, so the whole module is null
.
As a workaround, I imported directly from:
import Contacts from 'react-native-contacts/src/NativeContacts';
And it works, but I know this isn't safe or recommended for production.
My setup:
- React Native CLI (0.79.1)
[email protected]
- Android device
- Permissions granted via
PermissionsAndroid
- Metro reset &
gradlew clean
done Contacts
still resolves tonull
My question:
- Why is
Contacts
resolving tonull
even though TurboModule seems enabled? - Should I downgrade to
[email protected]
to avoid this? - What’s the correct and stable way to use
react-native-contacts
in a non-TurboModule setup?
Any help would be appreciated 🤝