opened
jdeanwaite
username_0
<!--
  We use GitHub Issues exclusively for tracking bugs in React Native.
  Questions? Visit http://facebook.github.io/react-native/help.html
  If this issue is about documentation or the website, please file it at:
  https://github.com/facebook/react-native-website/issues/new
-->

- [x] I have reviewed the [documentation](https://facebook.github.io/react-native)
- [x] I have searched [existing issues](https://github.com/facebook/react-native/issues)
- [x] I am using the [latest React Native version](https://github.com/facebook/react-native/releases)

<!-- Describe your issue in detail. -->

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
<!-- Required. Run `react-native info` in your terminal and paste its contents here. -->
```
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
<!-- 
  Required. Let us know how to reproduce the issue. Include a code sample, share a project, 
  or share an app that reproduces the issue using [Snack](https://snack.expo.io/).
-->
You can clone [my repository][https://github.com/username_0/missionary-training-app] and try out the command `react-native run-ios --device`.

## Expected Behavior
<!-- Write what you thought would happen. -->
I expected that it would run on my device.

## Actual Behavior
<!-- Write what happened. Include screenshots if needed. If this is a regression, let us know. -->
Build fails with an error described above.
Unable to run iOS on Device from Command Line - Simulator Works. RCT_METRO_PORT undefined
issue
created
hramos
username_1
RCT_METRO_PORT was added in https://github.com/facebook/react-native/commit/33d710e8c58ef1dc69816a59ac1cf390894e7cb9#diff-0822d6820d37285597b7a89988c8aea1 and it looks like someone else noticed the same behavior back then.

The author of the PR that culminated in that commit is @username_2. It looks like they left a comment on the PR that may help (see https://github.com/facebook/react-native/pull/16172).

@username_2 is there any way we can prevent people from running into this issue?
comment
created
DaKaZ
username_2
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
comment
created
jdeanwaite
username_0
@username_1, @username_2, thanks for your quick replies. @username_2 unfortunately running `RCT_METRO_PORT=8081 react-native run-ios --device` did not work. Same error is called. I looked up a bit higher in the console logs and noticed this as well. Not sure if it is related, but it referenced ports so I thought maybe it would be the case:
```
PhaseScriptExecution Start\ Packager /Users/me/projects/MyApp/ios/build/Build/Intermediates.noindex/React.build/Debug-iphoneos/React.build/Script-006B79A01A781F38006873D1.sh
    cd /Users/me/projects/MyApp/node_modules/react-native/React
    /bin/sh -c /Users/me/projects/MyApp/ios/build/Build/Intermediates.noindex/React.build/Debug-iphoneos/React.build/Script-006B79A01A781F38006873D1.sh

nc: port range not valid
```
comment
created
b45ch1
username_3
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(...)`.
comment
created
jdeanwaite
username_0
@username_3 Unfortunately for me, running by `uuid` is still not working. I receive the same build error of `RCT_METRO_PORT` being undefined.
comment
created
lizeqing
username_4
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
comment
created
gianpaj
username_5
@username_4 fix works. tested on  on `0.54.4`
comment
created
stdavis
username_6
Looks like this issue was fixed in: https://github.com/facebook/react-native/pull/17983

But no backport to 0.54. :(
comment
created
jdeanwaite
username_0
@username_6 Thanks for pointing this out! Looks like we'll just have to wait for 0.55! That is manageable. VSCode's [RN plugin](https://github.com/Microsoft/vscode-react-native) seems to rely on [ios-deply](https://github.com/phonegap/ios-deploy), so you can (create a debug configuration like so)[https://github.com/Microsoft/vscode-react-native/blob/master/doc/debugging.md#debugging-on-ios-device]:
```
    {
      "name": "Debug iOS Device",
      "program": "${workspaceRoot}/.vscode/launchReactNative.js",
      "type": "reactnative",
      "request": "launch",
      "platform": "ios",
      "sourceMaps": true,
      "outDir": "${workspaceRoot}/.vscode/.react",
      "target": "device"
    },
```
comment
closed
jdeanwaite
username_0
issue
created
jaygould
username_7
Just installed 0.55.0 and it's still happening, can anyone else confirm?
comment
created
ASteinheiser
username_8
Yes, try downgrading to react-native: 0.52.2, seems to have solved it for a few of us.
comment
created
chitezh
username_9
@username_1 This is still happening, why was it closed?
comment
reopened
jdeanwaite
username_0
<!--
  We use GitHub Issues exclusively for tracking bugs in React Native.
  Questions? Visit http://facebook.github.io/react-native/help.html
  If this issue is about documentation or the website, please file it at:
  https://github.com/facebook/react-native-website/issues/new
-->

- [x] I have reviewed the [documentation](https://facebook.github.io/react-native)
- [x] I have searched [existing issues](https://github.com/facebook/react-native/issues)
- [x] I am using the [latest React Native version](https://github.com/facebook/react-native/releases)

<!-- Describe your issue in detail. -->

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
<!-- Required. Run `react-native info` in your terminal and paste its contents here. -->
```
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
<!-- 
  Required. Let us know how to reproduce the issue. Include a code sample, share a project, 
  or share an app that reproduces the issue using [Snack](https://snack.expo.io/).
-->
You can clone [my repository](https://github.com/username_0/missionary-training-app) and try out the command `react-native run-ios --device`.

## Expected Behavior
<!-- Write what you thought would happen. -->
I expected that it would run on my device.

## Actual Behavior
<!-- Write what happened. Include screenshots if needed. If this is a regression, let us know. -->
Build fails with an error described above.
Unable to run iOS on Device from Command Line - Simulator Works. RCT_METRO_PORT undefined
issue
created
simplepanda
username_10
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?
comment
created
Axbon
username_11
Yup, we experience the same issue in 0.55 , same as #18673
comment
created
getaaron
username_12
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
```
comment
created
duro
username_13
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.
comment
created
omatrot
username_14
This issue is really affecting my development workflow as I'm running on a MacBook Air with limited disk space. Installing XCode is not an option.
comment
created
fadeojo
username_15
Any word on a work around for this issue?
comment
created
jdeanwaite
username_0
Personally I started using Expo as much as possible to avoid having to use the react native CLI to run projects. @username_14 this also does not require you to have XCode installed; I understand that Expo does not work for every project, but they have a lot of built-in native libraries now that I feel are able to solve most normal app needs.
comment
created
getaaron
username_12
@username_15 the only workarounds I know are to use expo or run your app from Xcode
comment
created
omatrot
username_14
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
comment
created
flyingxu
username_16
```
    "react": "^16.4.0",
    "react-native": "^0.55.4",
```
fixed the issue for me
comment
created
omatrot
username_14
@username_16 Yep same here :)
comment
created
vinicarra
username_17
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: 
macOS High Sierra 10.13.5
npm: 5.6.0
node: v8.11.3
xcode: 9.4.1
react-native: 0.55.4
react: 16.3.1
comment
created
acoulon99
username_18
Similar to @username_16 's solution, this fixed it for me. Note the difference in `react` version.
```
"react": "^16.3.1",
"react-native": "^0.55.4",
```
comment
created
santomegonzalo
username_19
Similar to @username_16 and @username_18 ... the new version **0.55.4** will fix the error

```bash
    "react": "16.3.1",
    "react-native": "0.55.4",
```
comment
closed
hramos
username_1
issue
created
Monte9
username_20
I didn't want to upgrade my RN version so @username_3 solution worked great! 🌮
comment
created
vincentvella
username_21
If you're trying to run it from an npm script instead of just the `react-native run-ios` you'll have to run the command like:
`npm run ios -- --udid e0452************************************`
-or-
`npm run ios -- --simulator="iPhone (whatever)"`
comment
created
dkfl1995
username_22
This really work, but dear hater-guys I`m longing to tell you that somewhat this command doesnt work - shell says that it is uncapable to install app to device. 
Yes. `If (error) shell will ask you to install "npm i -g ios-deploy"`... Try 't!
I install of ios-deploy finishes with error (what I had been faced with) run following shell command `npm i -g ios-deploy --unsafe-perms=true` or even not recommended `sudo npm i -g ios-deploy --unsafe-perms=true`...
thus all is done run `RCT_METRO_PORT=8081 react-native run-ios --device` like @username_0 said above...
You can change or remove RCT_METRO_PORT argument (removed argument defaults to :8081).
comment