React-native: `react-native run-ios --device` not behaving like `react-native run-android --device`

Created on 28 Jun 2018  路  24Comments  路  Source: facebook/react-native

Environment

Environment:
OS: macOS High Sierra 10.13.5
Node: 6.9.1
Yarn: 1.7.0
npm: 3.10.8
Watchman: 4.9.0
Xcode: Xcode 9.4.1 Build version 9F2000
Android Studio: Not Found

Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.4 => 0.55.4

Description

The react-native run-android --device command will build the application, install it on the device, and then launch the application on the device. The react-native run-ios --device command is not working completely: the command builds the application and installs it on the device correctly, however it will typically hang forever after that without ever launching the application. Most of the time it just hangs with the following message:

* BUILD SUCCEEDED *

installing and launching your app on [my device name]

Only on rare occasions does it get past this step and it then prints something like "shake the device and enable JS debugging", which will make everything work as expected. However this is exceedingly rare, the majority of the time the cli just hangs.

Reproducible Demo

  • Initialize a new project: react-native init TestRn
  • in XCode create the provisioning profile for the app
  • Run: react-native run-ios --device -- the majority of the time it will build and install correctly but it will almost always hang when trying to connect with the javascript debugger (at least that's what I suspect it's doing when it hangs).

Note I'm testing this on an iPhone with the following specs:

  • Version: 10.3.3
  • Model: ME553LL/A

What's more is that the app will install and launch correctly 100% of the time if it's run through XCode, however this isn't an option for me because I can't debug any of the react-native javascript in XCode (unless there is a way that I'm not aware of).

iOS Stale

Most helpful comment

I believe that react-native is a great platform and would like to see it spread. First time experience for novice users should just work.

I appreciate your effort in assisting, but it is not the first time I see well intentioned volunteers closing issues without proper understanding of the issue.

I am going to restate the issue as I see it, please read carefully (based on your comment above "see why it's not launching on the simulator" I see that it isn't clear yet what the problem is).

Summary: react-native run-ios on real device for barebones RN app created per official instructions does not launch the app and run-ios command never returns

  • install latest RN per instructions on site
  • generate a barebones project using react-native init
  • running on emulator experience:

    • $react-native run-ios

    • compiling window displays build messages, finally says build was successful then installing and launching message, app launches and the command ends returning back to the terminal console

    • all looks good :)

  • running on actual device:

    • $react-native run-ios --device myiPhoneName

    • all similar up to installing and launching message, then no progress, the command never returns back to cursor and there is no indication the app was deployed.

All 24 comments

@Sean-Brown Run it in Xcode and shake your device. Press "Debug JS Remotely." From there you can debug your app, as it launches in chrome. I have personally debugged RN from Xcode and WebStorm simultaneously on 0.56.0-rc.4.

What do you mean by "hang"? Where does it stop? This bug report is quite vague, I suggest you look into this issue further yourself.

Sorry I thought the description of the OP was clear enough, allow me to clarify further. What I mean by "hang" is that there is never progress, i.e. the app installs but never opens on the phone: it just sits there doing nothing. All that happens is the cli reports ** BUILD SUCCEEDED ** but nothing happens after that. On very rare occurrences it actually does get past that part and I'm able to do the "Debug JS Remotely" step, but most of the time nothing happens after "* BUILD SUCCEEDED *".

Please feel free to try the steps I outlined in the reproducible demo: I'm glad you can get it to work from XCode but as far as I can tell using the cli almost never works for iOS devices (Android devices work every time).

@Sean-Brown Have you tried opening the app manually? For me, compiling, launching, and debugging are all separate processes.

Opening the app manually results in the app displaying a message "downloading javascript bundle", followed by the app opening. After this I shook the phone and chose the option to "Debug JS Remotely", which caused the app to start re-downloading the app bundle before resulting in an error message during the download "Runtime is not ready for debugging - Make sure Packager server is running". If I had not shaken the phone and chose to "Debug JS Remotely" then none of my breakpoints would be hit.

It seems like the CLI gets into a bad state and isn't able to start the packager server, but it also never crashes or reports an error message so it just hangs.

I was able to finally get debugging working by:

  • running react-native start
  • then in VS Code choosing the "Attach to Packager" debugging option
  • then opening up the app on the iPhone, shaking the phone, and choosing the "Debug JS Remotely" option

I can work with this for now but I would prefer the simplicity of react-native run-ios --device (this works for android 100% of the time).

yep, that's how it works for me too. Turn this into a feature request on https://react-native.canny.io/, and you should probably close this issue.

I'll close this as an issue if the react-native run-ios --device command is "working as intended", although based on the behavior of the run-android command I'd expect that run-ios would work similarly.

Can you edit your original issue title and description to describe what you mean as working as intended?

running react-native start

react-native run-ios runs React Native in a new Terminal.app window automatically for me

then in VS Code choosing the "Attach to Packager" debugging option

React Native tooling can't do this step for you. This is editor-specific

then opening up the app on the iPhone,

I suppose opening up the app that could be automated.

shaking the phone, and choosing the "Debug JS Remotely" option

Shaking the phone and activating "Debug JS Remotely" should not be automatic. There are people who don't want this to be the default option. The app takes much longer to load for me when I don't use that option. I often use console.warn + Hot Reload to test because it's faster. It's possible to add a command line option to do that upon app launch.

The React Native core team has more pressing things to think about, such as React Native's internal redesign. External contributors are typically the ones to fix bugs. If this issue is particularly important to you, I encourage you to open a pull request. You can always install from your own fork or from a local directory.

The OP was essentially:

  • when I run react-native run-android --device it automatically builds and installs the application on my device, then launches the app on the device
  • when I run react-native run-ios --device it automatically builds and installs the application on my device, but it is unable to launch the app on the device and the CLI just hangs forever

I'm saying that the behavior of these two commands should be consistent.

Where I'm seeing this issue is in Visual Studio Code: I want to debug the application with the "Debug iOS" option. The "Debug Android" option works perfectly in VS Code but "Debug iOS" hangs forever.

Have you tried running the command on a normal shell? VS Code is unaffiliated with React Native.

Yeah I tried in the default Mac terminal as well as iTerm2 and they both were having the same issue with the react-native run-ios --devices command, which is why I thought there might be a CLI bug.

Please edit your original issue to reflect this new information. Maintainers are more likely to implement your idea if the title and issue body are correct.

OK and thanks for taking the time to work with me on this issue.

@CrazyPython Same issue i'm also facing. If run from the Xcode its running fine. If give command from webstorm terminal or mac terminal react-native run-ios --devices its stuck for ever and ever.

If you can launch it from your phone manually after running react-native run-ios, I think this is a minor issue. If you want to fix it yourself, go ahead. But it seems like the React Native community at large has bigger things to worry about.

I am running into this issue also, it repro's consistently in multiple installations of RN from scratch.

"If you can launch it from your phone manually after running react-native run-ios, I think this is a minor issue."

The fact that it says "installing and LAUNCHING" and then hangs is not minor. There is no indication the app was deployed, no progress indicator (except the first time when previously the app didn't exist on the phone.) You're essentially sitting waiting for a sign that it's done and nothing happens.

Please revisit the severity assessment.

What do you mean by hang? I'm fairly sure react-native-cli exits after the install process is over.

There is no indication the app was deployed, no progress indicator (except the first time when previously the app didn't exist on the phone.) You're essentially sitting waiting for a sign that it's done and nothing happens.

Granted, there is certainly a documentation issue here. I can understand your frustration if you expected the app to launch itself and you waited a long time. This

Please revisit the severity assessment.

I'm not in any way a member of the React Native team- I'm simply trying to assist them in prioritizing issues. I'd say this issue is just frustrating- and it's not the only outstanding frustrating issue for the React Native community, many community libraries have similar frustrating issue.

That being said the relevant code is here. You can edit out the "and launching" part, or you could dive deeper and see why it's not launching on the simulator. Over half of React Native's monthly code changes come from contributors, so don't be afraid to send a PR.

I believe that react-native is a great platform and would like to see it spread. First time experience for novice users should just work.

I appreciate your effort in assisting, but it is not the first time I see well intentioned volunteers closing issues without proper understanding of the issue.

I am going to restate the issue as I see it, please read carefully (based on your comment above "see why it's not launching on the simulator" I see that it isn't clear yet what the problem is).

Summary: react-native run-ios on real device for barebones RN app created per official instructions does not launch the app and run-ios command never returns

  • install latest RN per instructions on site
  • generate a barebones project using react-native init
  • running on emulator experience:

    • $react-native run-ios

    • compiling window displays build messages, finally says build was successful then installing and launching message, app launches and the command ends returning back to the terminal console

    • all looks good :)

  • running on actual device:

    • $react-native run-ios --device myiPhoneName

    • all similar up to installing and launching message, then no progress, the command never returns back to cursor and there is no indication the app was deployed.

I am experiencing this same exact issue. At first i thought it was a problem with vscode and react-native-tools but i seem to get the same experience from the command line. I have to start packager, attach to packager from vscode, then manually open app. When testing things like notifications where i have to put the app in the background and then click on the notification i get strange behavior like 'packager not ready for debug' or the chrome browser debug window flying open and colliding with vscode.

@bogdant, you're right. Can you see if the issue appears in

@StevePotter could you read @bogdant's post and try to fix the bug? You were the last person you who touched the code. Y'all could check if the issue appears in v0.49.4, making sure Product Name and Scheme are the same in Xcode.

I've run into this same issue - it's worth mentioning that if you change the jsCodeLocation from the network bundle to the local pre-bundled one, the issue no longer arises. This is almost definitely a network problem.

A dumb temporary workaround (sacrificing live reload):

#if TARGET_IPHONE_SIMULATOR
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
    jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif

Another viable workaround seems to be to use your device as a personal hotspot for your mac.

I think this is a regression, because it used to work before. Also it's not critical, because the app is being installed. But it ruins the developer experience sitting there waiting for it to finish, and probably cancelling and retrying, thinking that installation got stuck.

As a quick fix, if possible maybe we could add a log line saying "Installation succeeded" after the code that installs the IPA has finished, before it tries to launch the app. That way the developer knows that the app at least has been updated.

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

Was this page helpful?
0 / 5 - 0 ratings