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

[CLI] Changing packager port not supported when running run-ios, run-android #14113

Closed
hramos opened this issue May 23, 2017 · 11 comments
Closed
Labels
Help Wanted :octocat: Issues ideal for external contributors. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@hramos
Copy link
Contributor

hramos commented May 23, 2017

Description

It is not currently possible to launch an iOS or Android app and have it connect to a port other than the default of 8081. While it is possible to separately start the packager on a custom port, e.g. react-native start --port=8088, the above two commands are hardcoded to always attempt to start a packager on 8081.

This is troublesome on systems where port 8081 is already in use, as is the case with McAfee AV. Killing the process is not an option in this case.

Reproduction Steps and Sample Code

  1. Run react-native start --port=8088.
  2. Observe that packager is now running on port 8088:
┌────────────────────────────────────────────────────────────────────────────┐ 
│  Running packager on port 8088.                                            │ 
│                                                                            │ 
│  Keep this packager running while developing on any JS projects. Feel      │ 
│  free to close this tab and run your own packager instance if you          │ 
│  prefer.                                                                   │ 
│                                                                            │ 
│  https://github.com/facebook/react-native                                  │ 
│                                                                            │ 
└────────────────────────────────────────────────────────────────────────────┘ 
  1. Launch the iOS or Android app using react-native run-ios, react-native run-android.

If port 8081 is available, the run* command will launch another packager process on port 8081. If the port is not available, you will see the following error:

Port 8081 already in use, packager is either not running or not running correctly

This prevents the developer from launching the app, and effectively makes it so that React Native can only be developed on systems where port 8081 is available.

Solution

We still want run-ios and run-android to launch the packager if none is running, but we cannot assume the packager will always run on port 8081. We can add a port option to the CLI when run-ios or run-android are used.

We also need to update the iOS template as it has a hardcoded check on whether the packager is running on port 8081.

Finally, we need to make sure that once the app launches, it can successfully connect to whatever port is being used. This may require updates to the iOS, Android templates.

Additional Information

  • React Native version:
$ react-native --version
react-native-cli: 2.0.1
react-native: 0.44.0
  • Platform: iOS, Android
  • Development Operating System: macOS
@hramos
Copy link
Contributor Author

hramos commented May 23, 2017

@hramos hramos added the Help Wanted :octocat: Issues ideal for external contributors. label Jul 25, 2017
@adamweeks
Copy link

As a new user to RN who's work laptop will not let him kill the process running on 8081, this would be super helpful.

There also don't seem to be any proper instructions on the workaround for this. Lots of suggestions, none of which have worked for me yet.

@chtrinh
Copy link

chtrinh commented Aug 22, 2017

Fix for andriod: #15316

@cmdshepard
Copy link

@hramos Is this still outstanding for iOS?

@DaKaZ
Copy link

DaKaZ commented Sep 29, 2017

This is still an outstanding issue. I have a patch file which we use to setup both iOS and Android appropriately, but its cumbersome to have to apply it after EVERY yarn add/update. I think I have a good enough grasp on this problem to submit a PR, but before I do, I would like to ask @hramos if my approach is acceptable.

Basically, setting the port number via CLI is very difficult because of the vast number of different source files that reference the port number. As such, I am proposing that my PR use an environment variable for setting the port. As an example, to run on port 8088 (instead of the default 8081) you would run RCT_PACKAGER=8088 react-native run-ios or RCT_PACKAGER=8088 react-native run-android.

Please let me know if this is OK I'll get the PR pulled together ASAP.

@adamweeks
Copy link

@DaKaZ is it possible to have the --port option set the env variable, so it can be used with the feature added in #15316

@DaKaZ
Copy link

DaKaZ commented Oct 2, 2017

I have a submitted a PR for this issue. PR #16172 adds the port option to run-ios as you suggested would be best @adamweeks. @hramos please let me know if you'd like to discuss the approach at all, its a little bit of a monkey patch but I could not a non-fragile was of passing the port number into the objective-c code a BUILD time other than to directly edit the source files with sed. If someone with objective-c experience could suggest a better approach, I'd be happy to implement it, but this does work ;)

@stale
Copy link

stale bot commented Dec 1, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 1, 2017
@DaKaZ
Copy link

DaKaZ commented Dec 1, 2017

@hramos any way to speed up the PR review / approval process here. Stale bot is going to close our issue 😬

@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 1, 2017
facebook-github-bot pushed a commit that referenced this issue Jan 5, 2018
Summary:
The pull request adds the `--port` option to `run-ios` allowing a developer to build and launch a react-native app using a single command line like this:
```
react-native run-ios --port 8088
```

It defaults to the current port 8081.

This pull request fixes issue #9145 and issue #14113.

This patch also extends `run-android` to properly test and launch the packager with the specified port, extending the work done in PR:  ##15316

1. Create a new react-native app, or simply clone this branch and then update your version of react-native using `yarn add file:./path/to/this/fork/of/react-native`
2. run `react-native run-ios --port 8088`
3. watch the packager start on the desired port (8088 in this case) and watch your app in your simulator connect to the packager and launch the app.
Closes #16172

Differential Revision: D6612534

Pulled By: shergin

fbshipit-source-id: 50af449f5e4c32fb76ba95f4cb7bf179e35526d5
mathiasbynens pushed a commit to mathiasbynens/react-native that referenced this issue Jan 13, 2018
Summary:
The pull request adds the `--port` option to `run-ios` allowing a developer to build and launch a react-native app using a single command line like this:
```
react-native run-ios --port 8088
```

It defaults to the current port 8081.

This pull request fixes issue facebook#9145 and issue facebook#14113.

This patch also extends `run-android` to properly test and launch the packager with the specified port, extending the work done in PR:  #facebook#15316

1. Create a new react-native app, or simply clone this branch and then update your version of react-native using `yarn add file:./path/to/this/fork/of/react-native`
2. run `react-native run-ios --port 8088`
3. watch the packager start on the desired port (8088 in this case) and watch your app in your simulator connect to the packager and launch the app.
Closes facebook#16172

Differential Revision: D6612534

Pulled By: shergin

fbshipit-source-id: 50af449f5e4c32fb76ba95f4cb7bf179e35526d5
@stale
Copy link

stale bot commented Jan 30, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 30, 2018
@hramos
Copy link
Contributor Author

hramos commented Jan 31, 2018

This is now fixed, thanks @DaKaZ!

@hramos hramos closed this as completed Jan 31, 2018
@facebook facebook locked and limited conversation to collaborators May 15, 2018
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. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

5 participants