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

Unable to run iOS on Device from Command Line - Simulator Works. RCT_METRO_PORT undefined #18525

Closed
3 tasks done
justinwaite opened this issue Mar 23, 2018 · 32 comments
Closed
3 tasks done
Labels
Help Wanted :octocat: Issues ideal for external contributors. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@justinwaite
Copy link

justinwaite commented Mar 23, 2018

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.

@react-native-bot react-native-bot added Platform: iOS iOS applications. Platform: macOS Building on macOS. labels Mar 23, 2018
@hramos
Copy link
Contributor

hramos commented Mar 23, 2018

RCT_METRO_PORT was added in 33d710e#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 @DaKaZ. It looks like they left a comment on the PR that may help (see #16172).

@DaKaZ is there any way we can prevent people from running into this issue?

@hramos hramos added Help Wanted :octocat: Issues ideal for external contributors. 💻CLI labels Mar 23, 2018
@DaKaZ
Copy link

DaKaZ commented Mar 23, 2018

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

@justinwaite
Copy link
Author

justinwaite commented Mar 23, 2018

@hramos, @DaKaZ, thanks for your quick replies. @DaKaZ 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 has something to do with it as well:

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

@b45ch1
Copy link

b45ch1 commented Mar 24, 2018

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(...).

@justinwaite
Copy link
Author

@b45ch1 Unfortunately for me, running by uuid is still not working. I receive the same build error of RCT_METRO_PORT being undefined.

@lizeqing
Copy link

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

@gianpaj
Copy link

gianpaj commented Mar 30, 2018

@lizeqing 's workaround does work. tested on 0.54.4

@stdavis
Copy link

stdavis commented Mar 30, 2018

Looks like this issue was fixed in: #17983 and should be in 0.55.

But no backport to 0.54. :(

@justinwaite
Copy link
Author

justinwaite commented Mar 30, 2018

@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"
    },

@jaygould
Copy link

jaygould commented Apr 3, 2018

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

@ASteinheiser
Copy link

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

@chitezh
Copy link

chitezh commented Apr 6, 2018

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

@justinwaite justinwaite reopened this Apr 6, 2018
@dylanneild
Copy link

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?

@Axbon
Copy link

Axbon commented Apr 9, 2018

Yup, we experience the same issue in 0.55 , same as #18673

@getaaron
Copy link
Contributor

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

@duro
Copy link

duro commented Apr 20, 2018

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.

@grabvinod
Copy link

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.

@gonzaloreciog
Copy link

We're having this issue as well, any update or fix on this? thanks!

@omatrot
Copy link

omatrot commented May 9, 2018

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.

@fadeojo
Copy link

fadeojo commented May 10, 2018

Any word on a work around for this issue?

@justinwaite
Copy link
Author

Personally I started using Expo as much as possible to avoid having to use the react native CLI to run projects. @omatrot 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.

@getaaron
Copy link
Contributor

@fadeojo the only workarounds I know are to use expo or run your app from Xcode

@omatrot
Copy link

omatrot commented May 12, 2018

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

@omatrot
Copy link

omatrot commented May 29, 2018

Well on another Mac computer I have the problem with .0.55
And It does not compile with XCode /!
So basically I'm stuck with this particular machine.

Environment:
OS: macOS High Sierra 10.13.4
Node: 8.11.2
Yarn: 1.2.0
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.3.1 Build version 9E501
Android Studio: 3.1 AI-173.4720617

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

@flyingxu
Copy link

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

fixed the issue for me

@omatrot
Copy link

omatrot commented May 30, 2018

@flyingxu Yep same here :)

@vinicarra
Copy link

vinicarra commented Jun 19, 2018

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

@acoulon99
Copy link

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",

@santomegonzalo
Copy link

Similar to @flyingxu and @acoulon99 ... the new version 0.55.4 will fix the error

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

@hramos hramos closed this as completed Aug 8, 2018
@Monte9
Copy link
Contributor

Monte9 commented Sep 21, 2018

I didn't want to upgrade my RN version so @b45ch1 solution worked great! 🌮

@vincentvella
Copy link

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)"

@dkfl1995
Copy link

dkfl1995 commented Nov 27, 2018

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

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 @jdeanwaite said above...
You can change or remove RCT_METRO_PORT argument (removed argument defaults to :8081).

@facebook facebook locked as resolved and limited conversation to collaborators Aug 8, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted :octocat: Issues ideal for external contributors. Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests