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
Had the same problem!
For Android I can use adb to redirect port, but in iOS, cannot figure our a way to run React Native in a custom port. Have to take over the 8081 port from McAfee.
For those Mac user who cannot kill the McAfee process/service directly, you can unload it via launchctl
(macOS), then you can run the packager server on the default 8081 port.
cd /Library/LaunchDaemons
sudo launchctl unload com.mcafee.agent.macmn.plist
Also wrote a memo to explain the launchctl detail and MacOS boot flow.
I figured out the issue: for some reason I didn't kill the process on port 8081
and it was causing Xcode to fail.
Solution:
port 8081
.Xcode Menu > Product > Clean
.Resource:
React-Native Troubleshooting
My problem was the Wifi DNS setup..
i. Go to Settings-> Network.
ii. Select the connected Wifi, click Advance.
iii. Select DNS, you might have set your DNS server to 8.8.8.8 (God knows your intention ;) ). Delete it and set it to the default 192.168.1.1. Click OK.
iv. Run the react-native run-ios in terminal and it works.
With the help of other people's answers. I tried the following steps. It worked for me and hopefully for others. It only works for iOS. Let’s say we want to change the 8081 port to 8999 port.
First, Open Xcode.
Look at Project navigator(left) In [ProjectName]/[ProjectName]/AppDelegate.m:
Change
http://localhost:8081/index.ios.bundle?platform=ios&dev=true
to
http://localhost:8999/index.ios.bundle?platform=ios&dev=true
In Project navigator(left) [ProjectName]/ Libraries:
Click “React.xcodeproj”. On main panel, click “Build Phases” tag.
Expand “Run Script”, delete it with the cross.
In Project navigator(left) [ProjectName] / Libraries / RCTWebSocket.xcodeproj / RCTWebSocketExecutor.m : Search 8081 and replace it with 8999
Second open Finder
In the project root, open “package.json” :
Change the “script” attribute to :
{...
"start": "node_modules/react-native/packager/packager.sh --port=8999"
...
}
Then Open terminal
$cd to project root :
$ npm start
Cool! Then
Go back to Xcode and click the play button.
Cross your fingers.
Be Patient. There will be a blank in the client.
You can see it is doing building on the backend(terminal will log it).
The following steps worked for me for running react-native code on iOS and XCode 10.1
npm install @babel/runtime --save-dev
react-native run-ios --port=8088
. This will run the packager in 8088 port. I just had the same problem and found out Docker was using port 8081.
Therefore if you need to debug stuff with React Native, you need to stop docker, if it is using the same port.