Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSInternalInconsistencyException: bundleURL must be non-nil when not implementing loadSourceForBridge #9206

Closed
varungupta85 opened this issue Aug 4, 2016 · 11 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@varungupta85
Copy link
Contributor

I am using react-native 0.31.0-rc.1. I am observing the error in iOS on Mac.

I recently update react-native on my app to the latest and started to get this error (detailed error below). This only happens when I try to run the app on the phone by using Option 2 which is to load using a static bundle. I have tried:

  • Clean and rebuild in Xcode
  • Reset cache and run react packager
  • Uninstall the app on the phone
  • Coming from Windows background, I have also tried to reboot my machine

Error in Xcode

2016-08-04 09:34:37.611 GalarmApp[367:165469] *** Assertion failure in
-[RCTBatchedBridge loadSource:](), /Users/abc/Projects/GalarmApp/node_modules/react-native/React/Base/RCTBatchedBridge.m:180 2016-08-04 09:34:37.613 GalarmApp[367:165469] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleURL must be non-nil when not implementing loadSourceForBridge'
*** First throw call stack: (0x182b32db0 0x182197f80 0x182b32c80 0x1834b81c0 0x1000af788 0x1000adefc 0x1000adca4 0x1000e73d8 0x1000e7368 0x1000e6700 0x1000e643c 0x10005a254 0x10003cebc 0x10003c214 0x10003966c 0x100039b18 0x187d069c0 0x187f36184 0x187f3a5f0 0x187f37764 0x1844d37ac 0x1844d3618 0x1844d39c8 0x182ae909c 0x182ae8b30 0x182ae6830 0x182a10c50 0x187cff94c 0x187cfa088 0x10003bee0 0x1825ae8b8) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

I can see that this problem is printed here in the code but I am a beginner at best in native iOS development and don't know how to fix this problem.

Please help me in fixing this problem. Thanks!

Code in AppDelegate.swift file

/**
 * Loading JavaScript code - uncomment the one you want.
 *
 * OPTION 1
 * Load from development server. Start the server from the repository root:
 *
 * $ npm start
 *
 * To run on device, change `localhost` to the IP address of your computer
 * (you can get this by typing `ifconfig` into the terminal and selecting the
 * `inet` value under `en0:`) and make sure your computer and iOS device are
 * on the same Wi-Fi network.
 */
// let jsCodeLocation = NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios&dev=true")


 /**
 * OPTION 2
 * Load from pre-bundled file on disk. The static bundle is automatically
 * generated by "Bundle React Native code and images" build step.
 */
let jsCodeLocation = NSBundle.mainBundle().URLForResource("main", withExtension: "jsbundle")

print (jsCodeLocation)

let rootView = RCTRootView(bundleURL:jsCodeLocation, moduleName: "galarm", initialProperties: nil, launchOptions:launchOptions)

As you can see, I have commented out Option 1 and uncommented out 'Option 2. The jsCodeLocation is printed as nil. I have run the same app this way on the device like 100 times when I was usingreact-native 0.24.0`. I have not made any changes to the code and I started to see this error after the upgrade.

I have also asked this question on stackoverflow but since I was not getting any responses, I thought I will raise an issue here as well

@afeiship
Copy link

afeiship commented Aug 5, 2016

I have the same problem ~

@varungupta85
Copy link
Contributor Author

Please refer to the accepted answer for this question on stackoverflow. Looks like the IP detection for the ios bundle has been automated due to which the two options were removed and there is just one now.

@afeiship
Copy link

afeiship commented Aug 6, 2016

@varungupta85 Thank you,I have resolved the problem follow your advice.

This url:
http://stackoverflow.com/questions/38780325/running-react-native-app-on-ios-device-using-offline-bundle

If you change to a release scheme while building your app, that will compile your app with the offline bundle.

Product > Scheme > Edit Scheme > set build configuration to Release

@aleclarson
Copy link
Contributor

I sometimes get this error when using the development bundle (served by the packager).

Restarting the packager fixes it.

@gastonmorixe
Copy link

I solved by turning off WiFi in my mac and turning it on. Same on the iPhone.

@nevernet
Copy link

just using
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"]; to instead of jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

this solved my problem.

@esutton
Copy link

esutton commented Nov 16, 2016

None of these solutions worked for me when using:

        "react": "~15.3.1",
        "react-native": "0.37.0"

@nevernet had the best suggestion.

Go back to "old school" - it still works and I can debug again!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  // Comment-out, cannot get past error: bundleURL must be non-nil when not implementing loadSourceForBridge
  //jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

#if DEBUG
  NSLog(@"AppDelegate:DEBUG");

#if TARGET_IPHONE_SIMULATOR
  NSLog(@"AppDelegate:DEBUG:TARGET_IPHONE_SIMULATOR");
  jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
#else
  NSLog(@"AppDelegate:DEBUG:!TARGET_IPHONE_SIMULATOR");
  NSLog(@"To device debug, open RCTWebSocketExecutor.m & replace localhost with MacBook IP.");
  // Get dev host IP Address:
  //    ifconfig | grep inet\ | tail -1 | cut -d " " -f 2
  jsCodeLocation = [NSURL URLWithString:@"http://172.17.29.213:8081/index.ios.bundle"];
#endif

#else
  NSLog(@"AppDelegate:RELEASE jsbundle");
  jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

  NSLog(@"jsCodeLocation = %@",jsCodeLocation);


  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"BluetoothConnect"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

@asadakbar
Copy link

We were able to fix this without changing the jsCodeLocation code. It turns out that rn looks up the localhost ip either in the hosts file or because of the hosts file, I'm not good enough to read the Obj C to figure out exactly what its doing. I don't explicitly set localhost in our hosts files, as DNS will resolve it anyways, but because it isn't explicitly stated as 127.0.0.1 localhost, rn isnt able to grab the url of the device to store for offline bundle creation or interacting with the packager.

So the solution was to add the localhost line to the hosts file, and the error went away, without changing the scheme to release and without hardcoding the old jsCodeLocation code. I will say that it is also possible some people who do have the localhost line explicitly set in the hosts file may be having issues because the hosts file has been corrupted or is encoded incorrectly. I've read a bunch of places while hunting for the solution to this problem that osx fails to read the hosts file if it has those issues.

I've updated the so question here as well with what I've found http://stackoverflow.com/questions/38780325/running-react-native-app-on-ios-device-using-offline-bundle/40730709#40730709.

@guilhermedecampo
Copy link

thanks for the tip @aleclarson 🎉

@sarveshtelang
Copy link

Still getting the same error. Tried all of it. Can someone help?

Dec 12 18:34:41 tw-mbp-stelang logd[6406] : metadata shared cached uuid is null (using logd's shared cache info) AwesomeProject (11002)
Dec 12 18:34:41 tw-mbp-stelang logd[6406] : Failed to harvest strings for pathless uuid '00000000-0000-0000-0000-000000000000'
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : assertion failed: 15G1108 14B72: libxpc.dylib + 62597 [17F6B510-0FB1-30D3-B29C-D74A5D63719E]: 0x7d
Dec 12 18:34:41 tw-mbp-stelang Unknown[11002] :
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : [] nw_host_stats_add_src recv too small, received 24, expected 28
--- last message repeated 2 times ---
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : [] ____nwlog_simulate_crash_inner_block_invoke dlopen CrashReporterSupport failed
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : [] __nwlog_err_simulate_crash simulate crash failed "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
[x86_64] libnetcore-856.20.4
0 libsystem_network.dylib 0x000000010987d682 __nw_create_backtrace_string + 123
1 libnetwork.dylib 0x000000010a0ec932 nw_socket_add_input_handler + 3100
2 libnetwork.dylib 0x000000010a0ca4f4 nw_endpoint_flow_attach_protocols + 3768
3 libnetwork.dylib 0x000000010a0c9511 nw_endpoint_flow_setup_socket + 563
4 libnetwork.dylib 0x000000010a0c8270 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
5 libnetwork.dylib 0x000000010a0e344d nw_endpoint_handler_path_change + 1261
6 libnetwork.dylib 0x000000010a0e2e7c nw_endpoint_handler_start + 570
7 libnetwork.dylib 0x000000010a0faae5 nw_endpoint_resolver_start_next_child + 2240
8 libdispatch.dylib 0x00000
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : [] nw_host_stats_add_src recv too small, received 24, expected 28
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : [] __nwlog_err_simulate_crash simulate crash already simulated "nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available"
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : [] nw_socket_set_common_sockopts setsockopt SO_NOAPNFALLBK failed: [42] Protocol not available, dumping backtrace:
[x86_64] libnetcore-856.20.4
0 libsystem_network.dylib 0x000000010987d682 __nw_create_backtrace_string + 123
1 libnetwork.dylib 0x000000010a0ec932 nw_socket_add_input_handler + 3100
2 libnetwork.dylib 0x000000010a0ca4f4 nw_endpoint_flow_attach_protocols + 3768
3 libnetwork.dylib 0x000000010a0c9511 nw_endpoint_flow_setup_socket + 563
4 libnetwork.dylib 0x000000010a0c8270 -[NWConcrete_nw_endpoint_flow startWithHandler:] + 2612
5 libnetwork.dylib 0x000000010a0e344d nw_endpoint_handler_path_change + 1261
6 libnetwork.dylib 0x000000010a0e2e7c nw_endpoint_handler_start + 570
7 libnetwork.dylib 0x000000010a0faae5 nw_endpoint_resolver_start_next_child + 2240
8 libdispatch.dylib 0x00000
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : jsCodeLocation = (null)
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : Initializing <RCTBatchedBridge: 0x6180001998b0> (parent: <RCTBridge: 0x6180000bd640>, executor: RCTJSCExecutor)
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : *** Assertion failure in -RCTBatchedBridge loadSource:onProgress:, /Users/stelang/dev/AwesomeProject/node_modules/react-native/React/Base/RCTBatchedBridge.m:196
Dec 12 18:34:41 tw-mbp-stelang AwesomeProject[11002] : *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleURL must be non-nil when not implementing loadSourceForBridge'
*** First throw call stack:
(
0 CoreFoundation 0x000000010572834b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010463621e objc_exception_throw + 48
2 CoreFoundation 0x000000010572c442 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000104202d79 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4 AwesomeProject 0x0000000103d4f355 -[RCTBatchedBridge loadSource:onProgress:] + 997
5 AwesomeProject 0x0000000103d4d4c3 -[RCTBatchedBridge start] + 883
6 AwesomeProject 0x0000000103d8f60c -[RCTBridge setUp] + 684
7 AwesomeProject 0x0000000103d8e663 -[RCTBridge initWithDelegate:bundleURL:moduleProvider:launchOptions:] + 387
8 AwesomeProject 0x0000000103d8e472 -[RCTBridge initWithBundleURL:moduleProvider:launchOptions:] + 146
9 AwesomeProject 0x0000000103cebc27 -[RCTRootView initWithBundleURL:moduleName:initialProperties:launchOptions:] + 183
10 AwesomeProject 0x0000000103cc937a -[AppDelegate application:didFinishLaunchingWithOptions:] + 266
11 UIKit 0x0000000107c9a0be -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 290
12 UIKit 0x0000000107c9ba43 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4236
13 UIKit 0x0000000107ca1de9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
14 UIKit 0x0000000107c9ef69 -[UIApplication workspaceDidEndTransaction:] + 188
15 FrontBoardServices 0x000000010b127723 FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
16 FrontBoardServices 0x000000010b12759c -[FBSSerialQueue _performNext] + 189
17 FrontBoardServices 0x000000010b127925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
18 CoreFoundation 0x00000001056cd311 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
19 CoreFoundation 0x00000001056b259c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x00000001056b1a86 __CFRunLoopRun + 918
21 CoreFoundation 0x00000001056b1494 CFRunLoopRunSpecific + 420
22 UIKit 0x0000000107c9d7e6 -[UIApplication _run] + 434
23 UIKit 0x0000000107ca3964 UIApplicationMain + 159
24 AwesomeProject 0x0000000103cc974f main + 111
25 libdyld.dylib 0x000000010967068d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
Dec 12 18:34:41 tw-mbp-stelang SpringBoard[6412] : [KeyboardArbiter] HW kbd: Failed to set (null) as keyboard focus
Dec 12 18:34:41 tw-mbp-stelang com.apple.CoreSimulator.SimDevice.BFAC201D-7386-4604-844F-35B0E8A23E1F.launchd_sim[6395] (UIKitApplication:org.reactjs.native.example.AwesomeProject[0x6f37][11002]) : Service exited due to Abort trap: 6
Dec 12 18:34:41 tw-mbp-stelang assertiond[6416] : notify_suspend_pid() failed with error 7

@kyle-ssg
Copy link

kyle-ssg commented Jan 11, 2017

I got this when migrating a native project over to react native: check that the following is in your info.plist (right click it and edit as source).

<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSExceptionDomains</key>
		<dict>
			<key>localhost</key>
			<dict>
				<key>NSIncludesSubdomains</key>
				<true/>
				<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
				<true/>
			</dict>
		</dict>
	</dict>

Note, i did not have to "Go back to old school" - i'm still using jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests