react-native: RN 0.60.5 app on iOS crashes on startup: "RCTFatalException: Unhandled JS Exception: Native module cannot be null"
I’m trying to update my RN from 0.59.5 to 0.60.5. I was able to get Android app to work fine, but the same app on iOS (whose build completes successfully otherwise) crashes on cold app start with an RCTFatalException: Unhandled JS Exception: Native module cannot be null
error, right after the splash screen disappears. The Metro bundler doesn’t show any communication from the simulator/device; when the iOS app launches and crashes, the Metro bunder terminal output is unchanged.
This happens for both iOS Simulator and for real iOS devices running iOS 12.4 (iPhone SE, iPhone 8, and iPad 3rd generation).
Relevant facts:
- App worked perfectly fine for both iOS and Android when on 0.59.5
- With 0.60.5, app now only works for Android
- I used rn-diff-purge to update manually (via https://react-native-community.github.io/upgrade-helper/)
- I have added the missing
Start Packager
Build Script (from #25585) - My Metro bundler is on in a separate terminal window, using port 8081, registering no changes when the app launches on an iOS device/simulator
- I confirm that I still have the
localhost
exception in my Info.plist file - I have separate
index.android.js
andindex.ios.js
files, but don’t believe this should have made a difference (please correct me if I’m wrong). MyAppDelegate.m
contains the followingsourceURLForBridge
method (it uses CodePush when building the app for non-debug app, but this issue is purely for debug app):
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
#else
return [CodePush bundleURL];
#endif
}
Relevant Xcode debug output:
2019-08-19 16:54:48.466 [error][tid:com.facebook.react.JavaScript] Native module cannot be null.
2019-08-19 16:54:48.469051-0700 Skale[29480:811282] Native module cannot be null.
2019-08-19 16:54:48.473 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: Native module cannot be null.
2019-08-19 16:54:48.473052-0700 Skale[29480:811179] Unhandled JS Exception: Native module cannot be null.
2019-08-19 16:54:48.473 [error][tid:com.facebook.react.JavaScript] Module AppRegistry is not a registered callable module (calling runApplication)
2019-08-19 16:54:48.473480-0700 Skale[29480:811282] Module AppRegistry is not a registered callable module (calling runApplication)
2019-08-19 16:54:48.497285-0700 Skale[29480:811179] *** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Native module cannot be null.', reason: 'Unhandled JS Exception: Native module cannot be null., stack:
_@115:244
<unknown>@972:266
v@2:1474
<unknown>@971:241
v@2:1474
<unknown>@970:531
v@2:1474
<unknown>@968:269
v@2:1474
<unknown>@389:345
v@2:1474
<unknown>@388:98
v@2:1474
<unknown>@383:177
v@2:1474
<unknown>@370:340
v@2:1474
<unknown>@6:251
v@2:1474
d@2:876
global code@1030:4
'
*** First throw call stack:
(
0 CoreFoundation 0x00000001119508db __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000114998ac5 objc_exception_throw + 48
2 Skale 0x000000010efb6a7c RCTGetFatalHandler + 0
3 Skale 0x000000010efd9b4c -[RCTExceptionsManager reportFatalException:stack:exceptionId:] + 507
4 CoreFoundation 0x00000001119576ac __invoking___ + 140
5 CoreFoundation 0x0000000111954c25 -[NSInvocation invoke] + 325
6 CoreFoundation 0x0000000111955076 -[NSInvocation invokeWithTarget:] + 54
7 Skale 0x000000010efec84a -[RCTModuleMethod invokeWithBridge:module:arguments:] + 602
8 Skale 0x000000010efeec9d _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 251
9 Skale 0x000000010efeea1f ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 78
10 libdispatch.dylib 0x0000000116d28d7f _dispatch_call_block_and_release + 12
11 libdispatch.dylib 0x0000000116d29db5 _dispatch_client_callout + 8
12 libdispatch.dylib 0x0000000116d31225 _dispatch_lane_serial_drain + 778
13 libdispatch.dylib 0x0000000116d31e9c _dispatch_lane_invoke + 425
14 libdispatch.dylib 0x0000000116d3bea3 _dispatch_workloop_worker_thread + 733
15 libsystem_pthread.dylib 0x00000001186b1611 _pthread_wqthread + 421
16 libsystem_pthread.dylib 0x00000001186b13fd start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
React Native version:
System: OS: macOS 10.14.6 CPU: (8) x64 Intel® Core™ i7-6820HQ CPU @ 2.70GHz Memory: 24.93 MB / 16.00 GB Shell: 5.6.2 - /usr/local/bin/zsh Binaries: Node: 10.16.2 - /usr/local/bin/node Yarn: 1.7.0 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.4 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 Android SDK: API Levels: 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29 Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.0, 28.0.3, 29.0.0, 29.0.1 System Images: android-16 | Intel x86 Atom, android-16 | Google APIs Intel x86 Atom, android-17 | Google APIs Intel x86 Atom, android-18 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-21 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom IDEs: Android Studio: 3.4 AI-183.6156.11.34.5692245 Xcode: 10.3/10G8 - /usr/bin/xcodebuild npmPackages: react: 16.8.6 => 16.8.6 react-native: 0.60.5 => 0.60.5 npmGlobalPackages: create-react-native-app: 1.0.0 react-native-cli: 2.0.1 react-native-git-upgrade: 0.2.7 react-native-rename: 2.2.2
Steps To Reproduce
- Use changes prescribed by rn-diff-purge (https://react-native-community.github.io/upgrade-helper/) to manually update an existing working RN 0.59.5 app’s codebase
- Add missing
Start Packager
script in app’s Xcode Build Phases (from #25585) - Build using either
react-native run-ios
or through opening the .xcworkspace file and clicking the build (“run”) button; observe successful build - Launch the app and observe crash in Xcode debugger:
RCTFatalException: Unhandled JS Exception: Native module cannot be null
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 10
- Comments: 29 (8 by maintainers)
This problem is a bit tricky to debug, but it was due to an incompatible package. I’m also using
react-native-push-notification
which didn’t seem to work correctly for me. TheNative module cannot be null
error arises from the constructor innode_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js
.To debug which module was causing issues, I modified the constructor with the following patch (you could use a code break if you wanted, this is a quick and dirty hack):
Then when you run your app, it will print the stack trace allowing you to see where the error is coming from:
You can then click through to your component and see which module caused the invariant:
I’ve not quite figured out a fix for this yet, I’ll update this issue when I know what’s going on.
@oknechirik @emision @deepslam I’m curious, are any of you also using CodePush? Wondering if it’s related.
@ckOfor No luck yet. My issue is somewhat different from that of @janet-rivas – my app doesn’t even display that screen. The crash happens right after my splash screen goes away and just shows the default background color.