I'm encountering an issue with react-native-nfc-manager in a React Native Expo project, where I'm receiving the following warning: TypeError: Cannot convert null value to object
I'm using react-native-nfc-manager for NFC functionalities in my React Native Expo project. The warning occurs in a specific scenario, and I'm unsure about the cause or how to resolve it.
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View } from 'react-native';
import NfcManager, {Ndef, NfcTech, ByteParser} from 'react-native-nfc-manager';
export default function App() {
NfcManager.isSupported(NfcTech.MifareClassic)
.then(() => console.log('Mifare is supported'))
.catch(err => console.warn(err))
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
I am expecting that it returns Mifare is supported or not in the console. But it's rather returning Cannot convert null value to object
The error suggests that the native part is not configured correctly, which causes the
NfcManagerto be evaluated to null.First of all, be aware that
react-native-nfc-managerdoes not work with Expo Go, since it needs custom native code.I assume that you are not using Expo Go. In this case, check that you have added the config plugin to the plugins array of your
app.jsonorapp.config.jsNext, you need to rebuild your project as described in the expo documentation.