react-native: Unable to run iOS on Device from Command Line - Simulator Works. RCT_METRO_PORT undefined

I am unable to run my app on my iOS device via the command react-native run-ios --device. I am able to run it on the simulator via react-native run-ios and I am able to open the XCode project and run on my device directly from the project. When compiling, I receive the following error:

/Users/justin/VSCodeProjects/MyApp/node_modules/react-native/React/Base/RCTBundleURLProvider.m:17:53: error: use of undeclared identifier 'undefined'; did you mean 'underline'?
const NSUInteger kRCTBundleURLProviderDefaultPort = RCT_METRO_PORT;
                                                    ^~~~~~~~~~~~~~
                                                    underline
In file included from <built-in>:359:
<command line>:5:24: note: expanded from here
#define RCT_METRO_PORT undefined

Just from that message, it appears that RCT_METRO_PORT is undefined and causing the build to fail while using the command line to run the app on iOS on my device.

I have googled this error and nothing has come up to this point. Any ideas?

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 8.9.3
  Yarn: Not Found
  npm: 5.7.1
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: 16.3.0-alpha.1 => 16.3.0-alpha.1
  react-native: 0.54.2 => 0.54.2

Steps to Reproduce

You can clone my repository and try out the command react-native run-ios --device.

Expected Behavior

I expected that it would run on my device.

Actual Behavior

Build fails with an error described above.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 22
  • Comments: 32 (4 by maintainers)

Most upvoted comments

Just installed 0.55.0 and it’s still happening, can anyone else confirm?

I can confirm that react-native run-ios --device does not work on react-native version 0.54.2 As workaround, this works for me: ios-deploy -c to get the udid of my phone and then use react-native run-ios --udid e0452************************************ to compile and deploy the project to the phone.

To fix the issue, I believe one has to adapt the function runOnDevice(…) in file node_modules/react-native/local-cli/runIOS/runIOS.js and make it consistent with runOnDeviceByUdid(...) and runOnSimulator(...).

Hmmm, I am not entirely sure. I guess I always use Xcode to run on device so I had not run into this. A short term fix is likely andding RCT_METRO_PORT as an env var:

RCT_METRO_PORT=8081 react-native run-ios --device

I’ll try to look into this more

    "react": "^16.4.0",
    "react-native": "^0.55.4",

fixed the issue for me

seens it happen on https://github.com/facebook/react-native/blob/master/local-cli/runIOS/runIOS.js#L130:5 , just missing the port argument for buildProject function.

Simply add args.port at end of buildProject calling, it will work

@hramos This is still happening, why was it closed?

I am also getting this problem, but I don’t see any specific error coming out of the logs when app crashes. That said, launching from XCode works just fine. But app crashes immediately when launching from CLI.

I am still facing this issue on 0.55.0. Can anyone confirm if this is being fixed or fixed already or any work around.

@lizeqing 's workaround does work. tested on 0.54.4

Same issue here, the application builds with react-native run-ios but it instantly crash when it starts - the bundler created from npm start doesn’t ever connect to the application. However if I build the application directly from Xcode it successfully builds and opens but I want to use the react-native-cli in the building process due to some specefic debugging tools.

Environment: OS: macOS High Sierra 10.13.5 Node: 8.11.3 Yarn: Not Found npm: 5.6.0 Watchman: Not Found 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

@flyingxu Yep same here 😃

I am also experiencing this on 0.55. Here is my react-native info output in case that helps:

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 9.5.0
  Yarn: 1.3.2
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed)
  react: ^16.3.0-alpha.1 => 16.3.0-alpha.3
  react-native: 0.55.0 => 0.55.0

Similar to @flyingxu 's solution, this fixed it for me. Note the difference in react version.

"react": "^16.3.1",
"react-native": "^0.55.4",

0.55.0 also seems to break IntelliJ Idea based projects.

With 0.54.0 and earlier, running a project launches react-native-start which starts Metro on 8081, then in another run window, launches the command line Xcode build for the current project (if necessary), launches an iOS simulator, installs the new Xcode build, and then starts the app (which loads from Metro).

0.55.0 breaks this behaviour. In addition to the above RCT_METRO_PORT bug that breaks the Xcode command line build process, react-native-start now seems to try to start a second Metro process in a Terminal.app window that can’t start (undefined port).

Reverting to 0.54.0 is fine, though.

Anyone else seeing this?

@stdavis Thanks for pointing this out, looks like we’ll just have to wait for 0.55! That is manageable. VSCode’s RN plugin seems to rely on ios-deploy, so you can create a debug configuration like so:

    {
      "name": "Debug iOS Device",
      "program": "${workspaceRoot}/.vscode/launchReactNative.js",
      "type": "reactnative",
      "request": "launch",
      "platform": "ios",
      "sourceMaps": true,
      "outDir": "${workspaceRoot}/.vscode/.react",
      "target": "device"
    },

Upgrading to 0.55.0 did it for me. phew…

Environment: OS: macOS High Sierra 10.13.4 Node: 8.9.3 Yarn: Not Found npm: 5.8.0 Watchman: 4.9.0 Xcode: Not Found Android Studio: Not Found

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

Yes, try downgrading to react-native: 0.52.2, seems to have solved it for a few of us.