bugsnag / bugsnag-js

JavaScript error handling tool for BugSnag. Monitor and report JavaScript bugs & errors.
https://docs.bugsnag.com/platforms/javascript
MIT License
858 stars 253 forks source link

Expo SDK 43 Error: @react-native-community/netinfo: NativeModule.RNCNetInfo is null. #1600

Closed SudoGetBeer closed 2 years ago

SudoGetBeer commented 3 years ago

Describe the bug

If I use import Bugsnag from '@bugsnag/expo' I get this error log and the app crashes:

Error: @react-native-community/netinfo: NativeModule.RNCNetInfo is null. To fix this issue try these steps:

• Run `react-native link @react-native-community/netinfo` in the project root.
• Rebuild and re-run the app.
• If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
• Check that the library was linked correctly when you used the link command by running through the manual installation instructions in the README.
* If you are getting this error while unit testing you need to mock the native module. Follow the guide in the README.

If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-netinfo
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/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:204:6 in guardedLoadModule
at http://192.168.178.52:8081/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:130574:3 in global code

RCTBridge required dispatch_sync to load RCTDevLoadingView. This may lead to deadlocks
at node_modules/react-native/Libraries/Utilities/RCTLog.js:34:8 in logIfNoNativeHook

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.
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/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError

Environment

johnkiely1 commented 3 years ago

Hi @SudoGetBeer

Are you able to share some more details around your project? Is this an Expo managed workflow project? Did you install bugsnag via the cli or manually? And which version of @bugsnag/expo are you using?

Have you tried the suggestions given in that error message?

SudoGetBeer commented 3 years ago

Are you able to share some more details around your project?

It worked and then I upgraded to SDK 43 and building with EAS.

Is this an Expo managed workflow project?

Yes the managed workflow.

Did you install bugsnag via the cli or manually?

Tried both the cli and manual.

And which version of @bugsnag/expo are you using?

Bugsnag version: tried 7.14 and 7.13

Have you tried the suggestions given in that error message?

Yes but it just says:

react-native link @react-native-community/netinfo
warn Calling react-native link [packageName] is deprecated in favor of autolinking. It will be removed in the next major release.
Autolinking documentation: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
error Unknown dependency. Make sure that the package you are trying to link is already installed in your "node_modules" and present in your "package.json" dependencies.
info Run CLI with --verbose flag for more details.
johnkiely1 commented 3 years ago

Hi @SudoGetBeer ,

I've managed to reproduce what you are seeing. If you try the following it should work:

npm i @react-native-community/netinfo@6.0.2 and then react-native link @react-native-community/netinfo

Let me know if this works for you.

SudoGetBeer commented 3 years ago

The command works now. But the app still crashes until I remove the Bugsnag import.

SudoGetBeer commented 3 years ago

@johnkiely1 any other ideas?

stephenb commented 3 years ago

I'm getting the same issue.

johnkiely1 commented 3 years ago

@SudoGetBeer @stephenb

I wonder if this is related to using EAS build? EAS build is not something we have tested with so its plausible this is causing the issue. Would it be possible to test running this with npm run iosor expo run:ios to see if we can narrow it down to be EAS build related?

SudoGetBeer commented 3 years ago

@johnkiely1 I had the same error when using expo start --dev-client. If that helps. npm run ios or expo run:ios dont work for me. But I build a new testflight version with expo build:iosand will test that

SudoGetBeer commented 3 years ago

It seems it is the eas. With the old build the app don't crash on startup

stephenb commented 3 years ago

@johnkiely1 Yes, I am in the process of switching to using EAS build. I'm assuming bugsnag's expo client had been assuming netinfo was natively available, but that has changed with EAS... but, I'm still getting up to speed on how this all works so not too certain.

johnkiely1 commented 3 years ago

I did come across this, https://forums.expo.dev/t/eas-build-does-not-install-dependencies-defined-in-other-node-modules/59178 which seems related. There is also this suggestion here which might help. Perhaps there is a way to ensure the netinfo dependency is loaded correctly via some EAS build config. I'm not sure what that would be as I'm not at all familiar with EAS build as it is not something that is officially supported by Bugsnag. We have a roadmap item to look into supporting it the future but we don't have an estimate for when this might be as yet.

mattdyoung commented 2 years ago

Closing, as we believe this is a build issue related to EAS.

We plan to consider official support for Expo EAS Build in the future.

stephenb commented 2 years ago

OK, and just to update the thread, I did fix my build by manually adding the netinfo dependency. Perhaps best-practice wrt EAS Build will be for 3rd party libs to specify these dependencies, but I'm not totally sure. Expo is moving towards EAS Build being the primary build process though, as the old build process will be phased out.

PavleNeskovic commented 8 months ago

If anyone still has the issue using dev client, try running npx expo prebuild and then eas build --platform all. That was the issue on my end.

ravishukla21 commented 3 months ago

It works on expo go but on running on development build it gives error

ERROR Error: @react-native-community/netinfo: NativeModule.RNCNetInfo is null. To fix this issue try these steps:

• Run react-native link @react-native-community/netinfo in the project root. • Rebuild and re-run the app. • If you are using CocoaPods on iOS, run pod install in the ios directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods. • Check that the library was linked correctly when you used the link command by running through the manual installation instructions in the README.

If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-netinfo, js engine: hermes