react-native-nfc-manager Warning: TypeError - Cannot convert null value to object in React Native Expo

150 Views Asked by At

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

1

There are 1 best solutions below

0
David Scholz On BEST ANSWER

The error suggests that the native part is not configured correctly, which causes the NfcManager to be evaluated to null.

First of all, be aware that react-native-nfc-manager does 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.json or app.config.js

{
  "expo": {
    "plugins": ["react-native-nfc-manager"]
  }
}

Next, you need to rebuild your project as described in the expo documentation.