Description
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
- Run
react-native start --port=8088
. - 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 │
│ │
└────────────────────────────────────────────────────────────────────────────┘
- 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