I have a React Native app built using Expo and I am trying to configure permissions using react-native-permissions
library. To test the app I am using Expo Go on my iPhone.
When running my react native app on Expo Go, I get the following errors:
ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNPermissionsModule' could not be found. Verify that a module by this name is registered in the native binary., js engine: hermes
ERROR Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes
I have tried removing the following code: Afterwards the app works as normal and the error messages doesn't appear. So it is likely that it is being caused by the react-native-permissions
library.
useEffect(() => {
check(PERMISSIONS.IOS.LOCATION_WHEN_IN_USE)
.then((result) => {
if( result === RESULTS.GRANTED || result === RESULTS.LIMITED){
setLocationPermission(true);
}
else{
setLocationPermission(false);
}
})
console.log(locationPermission);
}, []);
But I still get the error if I remove that code and still import the library:
import {check, PERMISSIONS, RESULTS} from 'react-native-permissions';
I have found similar questions posted, but none of them answer my question.
I have found a solution, for anyone else who has a similar issue.
If you are using Expo to build your react native app, then it is better to use expo-location
library instead. Expo also offer other libraries for helping you access other permissions.
expo-location
also allows you to access the location information as well as request permission.
I'm not sure why I was getting the error with the previous library (possibly because it was incompatible with Expo) but this solution worked for me.