I\'m trying to get up and running with React Native and I am seeing the message below in Xcode:
Port 8081 already in use, packager is either not running
In "react" 16.8.6 and "react-native": "0.60.5"
Go to [YOURPROJECT] > ios > [YOURPROJECT].xcodeproj > project.pbxproj
CHANGE THE RCT_METRO_PORT TO YOUR PORT(EX: 8089)
Clean and build. It should work.
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";
Update:
"react": "16.8.3", "react-native": "0.59.8",
node_modules > react-native > React > React.xcodeproj
Change the port from 8081 to 8082
In other versions of the react-native, search for the string RCT_METRO_PORT
or already in use,
. In result found, change the port from 8081 to the desired port(ex: 8082).
I had the same issue running react-native run-ios ----port=8088
worked for me, did not try android yet
Easy method: Try with the following code
kill -9 $(lsof -t -i:8081)
If you do lsof -n -i4TCP:8081
as recommended in Facebook's troubleshooting page and get an empty result, try again using sudo lsof -n -i4TCP:8081
.
In my case, it turns out McAfee anti-virus software is running process that listens on that port. Killing that process (I know, I know!) fixed the problem.
run the following command:
react-native start --port=8088
I had the same issue with McAfee running on 8081. This worked for me.
https://facebook.github.io/react-native/docs/troubleshooting.html
Try the following steps for those that need to change port 8081 to a different port.
> npm start
will launch node_modules/react-native/packager/packager.sh
In there it will merge command line parameters, i.e. --port into the predefined options. i.e. port=8081
I updated the package.json start
option to include my prefered port, as i was unable to stop existing services using this port.
{
"name": "AwesomeProject",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node_modules/react-native/packager/packager.sh --port=8999"
},
"dependencies": {
"react-native": "^0.12.0"
}
}
** Note that this may not work for android which is apparently hard coded to 8081 Stack Post Here
Building Xcode When building Xcode it will still fail as it tries to run a script to launch node. You will either need to remove this script from the build process or update it to the new port.
Under libraries
select React.xcodeproj
. In the main screen select Build Phases
. You will see Run Script
.
Either remove this entry, having called npm start
yourself, or edit the port.
if nc -w 5 -z localhost 8999 ; then
if ! curl -s "http://localhost:8999/status" | grep -q "packager-status:running" ; then
echo "Port 8999 already in use, packager is either not running or not running correctly"
exit 2
fi
else
open $SRCROOT/../packager/launchPackager.command || echo "Can't start packager automatically"
fi
Debugging Seems 8081 is all over the shop. Need to additionally updated the RCTWebSocketExecutor.m under xcode-project: Libraries/RCTWebSocket.xcodeproj
- (instancetype)init
{
return [self initWithURL:[RCTConvert NSURL:@"http://localhost:8999/debugger-proxy"]];
}
** Launching packager from iOS ** If launching only from iOS then you additionally need to edit launchPackager.command to add in the appropriate port as this file is used by Xcode to run the javascript.
$THIS_DIR/packager.sh --port=8999