Reputation: 7111
So I'm getting started with React Native. Honestly working with XCode has been one of the most miserable development experiences I've experienced in my life. The simulator literally takes 20+ minutes to boot up (is this normal??) and when it does I can't launch the app because it's on port 8081 which apparently something else is running on so it just crashes. So now I have to change it and probably wait another 30 minutes for the simulator to boot up.
My question is, what is the best way to change the port number in a React Native iOS app. I've seen references to the appDelegate.m file but it seems that it's not allowing you to change it in this file anymore because I see no reference to localhost:8081 anywhere in it.
Any help would be appreciated. I also have tried react-native start --port 9988
this starts a terminal session and looks like it's working but doesn't launch xcode, the simulator or anything. When I launch Xcode and then run the app from here it launches another terminal session pointing to port 8081 pretty much just undoing what I did.
Been basically sitting and waiting on xcode for the last 5 hours. Super frustrating. Just wanna start coding!!
Thanks!
Upvotes: 2
Views: 3086
Reputation: 1583
In react-native: 0.60.5
Go to > [Your Project] > ios > [Your Project].xcodeproj > project.pbxproj. Search for 8081 and replace all the port 8081 to 8089(example)
shellScript = "export RCT_METRO_PORT=\"${RCT_METRO_PORT:=8089}\"\necho \"export RCT_METRO_PORT=${RCT_METRO_PORT}\" > \"${SRCROOT}/../node_modules/react-native/scripts/.packager.env\"\nif [ -z \"${RCT_NO_LAUNCH_PACKAGER+xxx}\" ] ; then\n if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then\n if ! curl -s \"http://localhost:${RCT_METRO_PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\n else\n open \"$SRCROOT/../node_modules/react-native/scripts/launchPackager.command\" || echo \"Can't start packager automatically\"\n fi\nfi\n";
Upvotes: 0
Reputation: 7126
Had the same problem,
I found that the React library takes a user defined setting to change the default port : RCT_METRO_PORT
in : -> Libraries -> React.xcodeproj -> Build Settings -> Add user defined setting
i added this and it solved my problem
Upvotes: 4