0

When run LogRocket in expo go has this error:

Invariant Violation: Native module cannot be null.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in ErrorUtils.setGlobalHandler$argument_0
Steve Phuc
  • 1,168
  • 2
  • 11
  • 12

1 Answers1

-1

Based on this guide https://docs.expo.dev/bare/using-expo-client/#use-conditional-inline-requires-to-provide-fallbacks

create a file LogRocketInit.js

import Constants from 'expo-constants';
import { useEffect } from 'react';


export default function LogRocketInit() {
  useEffect(() => {
    if (Constants.appOwnership !== 'expo') {
      const LogRocket = require('@logrocket/react-native');
      LogRocket.init('****');
    }
  }, []);

  return null;
}

then add it to App.js as normal

export default function App() {
  return (
       ...
       <LogRocketInit />
       ...
}

in case you need to use it in another place, use this

   if (Constants.appOwnership !== 'expo') {
      const LogRocket = require('@logrocket/react-native');
      ....
   }
Steve Phuc
  • 1,168
  • 2
  • 11
  • 12