cli
cli copied to clipboard
--port parameter is not used by packager on MacOS
Environment
System: OS: macOS 10.15.6 CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz Memory: 153.58 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 12.16.1 - /usr/local/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 6.13.4 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.9.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2 Android SDK: Android NDK: 20.0.5594570 IDEs: Android Studio: 4.0 AI-193.6911.18.40.6514223 Xcode: 11.6/11E708 - /usr/bin/xcodebuild Languages: Java: 11.0.7 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: ^0.62.2 => 0.62.2 npmGlobalPackages: react-native: Not Found
Description
It is not possibel to use different port than 8081 on MacOS because the packager ignores ---port from command line or the parameter is not passed through the packager invocation. A side effect is cli is checking running packager on custom port and did not find it. as a result the packager is started twice or more with port 8081
Reproducible Demo
react-native run-android --port=18089
Would you like to tackle this issue? :)
I was able to successfully run on a different port when running:
react-native start --port XX
react-native run-android --port XX
Can you check yourself?
Now I tried to run react-native run-android --port XX
only and it seems that Metro is opened on wrong port indeed. @Taym95 because you've already worked on this, can you make sure to verify why the port is not passed correctly to Metro? I'm not convinced we need to pass it in yet another place like proposed here #1260 but maybe that's the case actually. Would like to have this fixed properly and not monkey-patch whatever works.
Now I tried to run
react-native run-android --port XX
only and it seems that Metro is opened on wrong port indeed. @Taym95 because you've already worked on this, can you make sure to verify why the port is not passed correctly to Metro? I'm not convinced we need to pass it in yet another place like proposed here #1260 but maybe that's the case actually. Would like to have this fixed properly and not monkey-patch whatever works.
Yes sure, I will deep investigate this issue.
Thank you @Taym95
Now I tried to run
react-native run-android --port XX
only and it seems that Metro is opened on wrong port indeed. @Taym95 because you've already worked on this, can you make sure to verify why the port is not passed correctly to Metro? I'm not convinced we need to pass it in yet another place like proposed here #1260 but maybe that's the case actually. Would like to have this fixed properly and not monkey-patch whatever works.
Sorry for the late reply. This is exactly our use case. We use VS Code and the command line to start the simulator only with the run-android or run-ios command.
Hello,
Any progress here? Why is the PR closed but not merged. Did I miss something? This problem is realy annyoing. We need to use a different port because on 8081 a third party corporate application is running in our company.
Regards, Stephan
HI, the PR does not solve the problem correctly, working to fix this issue properly.
Any news here?
Not quite. Would you like to give us a hand on this one?
Hi I have looked deep into a similar issue for both iOS and android. If anyone wants to fix this read: https://gist.github.com/Pirsanth/9d7fd53a5b6f64a8f6d84f07d7e62c01
If it helped please give me a clap on medium (I like internet points): https://pirsanth.medium.com/how-to-run-2-different-react-native-apps-on-2-different-emulators-devices-at-the-same-time-9783176fc81b
react-native run-android --port XX
seems to only affect the installed app, not the packager it starts.
For example, if packager has not started, react-native run-android --port 1234
starts packager listening to port 8081 (default port), and launches app listening to port 1234.
To make react-native run-android --port XX
work, I need to start the packager separately with specific port i.e. react-native start --port 1234
followed by react-native run-android --port 1234
.
Another option is adding following to metro.config.js
:
module.exports = {
...
server: {
port: 1234, // <---- Add here
},
};
Then the packager started by react-native run-android --port 1234
would listen to port 1234, and react-native start
would listens to port 1234 by default. Note that metro.config.js
only applies to the packager. You still need to provide --port
to react-native run-android
.
There hasn't been any activity on this issue in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
So it looks like this issue no longer occurs - I ran npx react-native run-android --port 8088
and packager started on 8088 port, and emulator connected to the packager without any problems. I think this issue was fixed by another PR "by accident" :)
https://user-images.githubusercontent.com/63900941/237035074-9e1d9783-349d-483d-9cbf-c589cd8bb58f.mp4