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

react-native run-ios doesn't start packager in debug mode if React is linked via Pods #317

Closed
noahtallen opened this issue Apr 14, 2019 · 21 comments
Labels
bug Something isn't working on hold

Comments

@noahtallen
Copy link

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.4
      CPU: (8) x64 Intel(R) Core(TM) i7-4960HQ CPU @ 2.60GHz
      Memory: 3.11 GB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.8.0 - /usr/local/bin/node
      Yarn: 1.13.0 - /usr/local/bin/yarn
      npm: 6.9.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 27.0.3, 28.0.3
        System Images: android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
      Xcode: 10.2/10E125 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.4 => 0.59.4 

Description

At some point through my iOS "journey", I must have disabled launching the packager. I think this happened at the same time I started linking react native exclusively through Pods. As a result, I have no React libs imported into the xcode project manually. I got rid of all of that and did it all through Pods, which has been working much better for linking other libraries!

Anyways, when I did that, it stopped launching the packager, so now I have to do it manually. I suppose I'm wondering A) how do I turn that back on? and B) is it possible the CLI should check and launch the packager itself if it was not launched during the build process?

@noahtallen noahtallen added the bug Something isn't working label Apr 14, 2019
@thymikee
Copy link
Member

cc @lucasbento as he's working on similar field in #310. Feel free to check it out and suggest improvements!

@lucasbento
Copy link
Member

@noahtallen: thanks for opening this issue!

By doesn't always do you mean that it launches the packager sometimes and other times not?

Would you be able to provide a small repo with a code that I can reproduce locally?

@noahtallen
Copy link
Author

noahtallen commented Apr 15, 2019 via email

@lucasbento
Copy link
Member

@noahtallen: alright, I'll wait for the project then.

@noahtallen
Copy link
Author

Howdy! Here's a repo reproducing the issue: test-react-native-packager. Please let me know if you have any questions. You should be able to see instructions in the readme. The rational behind removing the manually linked react is that I got so many build errors conflicting with other Pods and whatnot when I had it linked both ways! Having it this way has really reduced the amount of friction our team has when working with third party dependencies. If I'm not wrong, this is how it would be set up if one was adding react-native to an existing iOS project.

@lucasbento
Copy link
Member

@noahtallen: cool, I'll check it out!

@lucasbento
Copy link
Member

@noahtallen: FYI I see that you mentioned that you couldn't build it, I updated my local cocoapods to 1.6.1 and did this to get it to run: CocoaPods/CocoaPods#8091 (comment).

@lucasbento
Copy link
Member

So, as per what I can see this is because the target React on Pods doesn't have a start packager build phase as it does when you use it without pods.

Without pods

image

With pods

image

I believe I can include the script to start the packager here by doing something like https://stackoverflow.com/a/20505234/4252781, I don't have much experience with this so I am not sure.

@thymikee / @grabbou would you be able to point someone that can check if this is the right thing to do or not?

@thymikee
Copy link
Member

cc @alloy @orta our lovely CocoaPods experts! :)

@orta
Copy link
Member

orta commented Apr 17, 2019

The file React.podspec will want that script adding via script_phases key 👍

@grabbou
Copy link
Member

grabbou commented Apr 17, 2019 via email

@orta
Copy link
Member

orta commented Apr 17, 2019

That can work, you can see how the support works here: https://github.com/react-native-community/cli/blob/master/packages/platform-ios/native_modules.rb#L43-L62

I should get some docs on this out

@lucasbento
Copy link
Member

I tried to investigate more of this but I don't really understand how this would fit in the autolinking, I'll be waiting for @orta's docs.

@ou2s
Copy link

ou2s commented May 28, 2019

Also having this issue after linking react native exclusively with Cocoapods during 0.59.5 update. In our case the issue is ALWAYS occurring in Debug. So please change the title of the issue as @noahtallen confirmed it is the same for him.

I found a workaround:

  • Add manually the Build Phase script and change the path of the launchPackager.command. Below you'll find the modified script
export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"
echo "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../node_modules/react-native/scripts/.packager.env"
if [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then
  if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then
    if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then
      echo "warning: Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"
      exit 2
    fi
  else
    open "$SRCROOT/../node_modules/react-native/scripts/launchPackager.command" || echo "warning: Can't start packager automatically"
  fi
fi

@noahtallen noahtallen changed the title react-native run-ios does not always launch packager react-native run-ios does not launch packager in debug mode when React is linked exclusively through Pods May 29, 2019
@noahtallen noahtallen changed the title react-native run-ios does not launch packager in debug mode when React is linked exclusively through Pods react-native run-ios doesn't start packager in debug mode if React is linked via Pods May 29, 2019
@noahtallen
Copy link
Author

I tried to put the meat of the issue in the title ;) @ou2s

@vinchentsoKN
Copy link

So, as per what I can see this is because the target React on Pods doesn't have a start packager build phase as it does when you use it without pods.

Without pods

image

With pods

image

I believe I can include the script to start the packager here by doing something like https://stackoverflow.com/a/20505234/4252781, I don't have much experience with this so I am not sure.

@thymikee / @grabbou would you be able to point someone that can check if this is the right thing to do or not?

I had a problem after upgrade to RN 0.60 - The packager wasn't starting
Using your package script I have managed to run it ! :)

@orta
Copy link
Member

orta commented Sep 6, 2019

Yep, I can confirm moving the script into your app target's build phases is the right thing to do

I think the react-native upgrade tool would need to add support for checking that there are no build phases which start the package

@thymikee thymikee closed this as completed Mar 9, 2020
@chrisbobbe
Copy link

chrisbobbe commented May 19, 2020

@orta said:

Yep, I can confirm moving the script into your app target's build phases is the right thing to do

Ah, OK, thanks, I've managed to do that (zulip/zulip-mobile@33f4b41).

@lucasbento said:

So, as per what I can see this is because the target React on Pods doesn't have a start packager build phase as it does when you use it without pods.

That sounds right. I'm seeing the same as what's in those screenshots.

Hmm, so, a solution like this one —

@orta said:

The file React.podspec will want that script adding via script_phases key 👍

— isn't being considered anymore, it sounds like. (Why, I wonder?)

IIUC, though, doesn't that mean that improvements like facebook/react-native@4ea6204 have no effect for people on RN v0.60.0 and above, where v0.60.0 is the version when CocoaPods is newly officially favored? At least, not unless people manually update the script in their own app target's build phases? These changes (some also new in v0.60) are hard to keep up with, as they don't appear in rn-diff-purge or the comments in the upgrade helper.

@chrisbobbe
Copy link

chrisbobbe commented May 20, 2020

I said:

they don't appear in rn-diff-purge or the comments in the upgrade helper.

See also my post in Upgrade Support, at react-native-community/upgrade-support#76.

@lifenautjoe
Copy link

Also having this issue after linking react native exclusively with Cocoapods during 0.59.5 update. In our case the issue is ALWAYS occurring in Debug. So please change the title of the issue as @noahtallen confirmed it is the same for him.

I found a workaround:

  • Add manually the Build Phase script and change the path of the launchPackager.command. Below you'll find the modified script
export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"
echo "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../node_modules/react-native/scripts/.packager.env"
if [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then
  if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then
    if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then
      echo "warning: Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"
      exit 2
    fi
  else
    open "$SRCROOT/../node_modules/react-native/scripts/launchPackager.command" || echo "warning: Can't start packager automatically"
  fi
fi

Hi everyone,

I've added this script to the app Build Phases (as @orta suggested) -> Run Script but see no change.

Is there something else to do to make the packager start automatically?

image

@Voltron369
Copy link

Voltron369 commented Dec 3, 2020

uncheck "For install builds only"

Also having this issue after linking react native exclusively with Cocoapods during 0.59.5 update. In our case the issue is ALWAYS occurring in Debug. So please change the title of the issue as @noahtallen confirmed it is the same for him.
I found a workaround:

  • Add manually the Build Phase script and change the path of the launchPackager.command. Below you'll find the modified script
export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"
echo "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../node_modules/react-native/scripts/.packager.env"
if [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then
  if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then
    if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then
      echo "warning: Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"
      exit 2
    fi
  else
    open "$SRCROOT/../node_modules/react-native/scripts/launchPackager.command" || echo "warning: Can't start packager automatically"
  fi
fi

Hi everyone,

I've added this script to the app Build Phases (as @orta suggested) -> Run Script but see no change.

Is there something else to do to make the packager start automatically?

image

uncheck "For install builds only"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working on hold
Projects
None yet
Development

No branches or pull requests

10 participants