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

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?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 21 (12 by maintainers)

Most upvoted comments

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

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

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 tried to put the meat of the issue in the title 😉 @ou2s

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

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

cc @alloy @orta our lovely CocoaPods experts! 😃

@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: https://github.com/CocoaPods/CocoaPods/issues/8091#issuecomment-421538684.