I'm trying to get up and running with react native and I am seeing the below message in xcode. I went to the react native Troubleshooting page and tried to kill port 8081 process, but I'm still getting the same issue. Also, I have attached a screenshot of what I am seeing in xcode. Any help would be fully appreciated.
我试图站起来,以响应本地的方式运行,我在xcode中看到了下面的消息。我进入了react native故障排除页面并试图杀死端口8081进程,但我仍然得到了相同的问题。另外,我还附上了我在xcode中看到的截图。任何帮助都将得到充分的感谢。
Port 8081 already in use, packager is either not running or not running correctly Command /bin/sh failed with exit code 2
已经在使用的端口8081,packager要么没有运行,要么没有正确运行命令/bin/sh以退出代码2失败。
8 个解决方案
#1
4
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.
在别人的帮助下。我尝试了以下步骤。这对我和其他人都有帮助。它只适用于iOS。假设我们想将8081端口更改为8999端口。
First, Open Xcode.
首先,打开Xcode。
-
Look at Project navigator(left) In [ProjectName]/[ProjectName]/AppDelegate.m:
在[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.
点击“React.xcodeproj”。在主面板上,点击“构建阶段”标签。
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
在项目导航器(左)[ProjectName] /库/ RCTWebSocket中。xcodeproj / RCTWebSocketExecutor。m:搜索8081,用8999替换。
Second open Finder
第二个开放仪
In the project root, open “package.json” :
在项目根中打开“包”。json”:
Change the “script” attribute to :
将“脚本”属性更改为:
{...
"start": "node_modules/react-native/packager/packager.sh --port=8999"
...
}
Then Open terminal
然后打开终端
-
$cd to project root :
$cd至项目根:
$ npm start
美元npm开始
Cool! Then
太酷了!然后
Go back to Xcode and click play button.
回到Xcode,点击play按钮。
Cross your fingers.
交叉你的手指。
Be Patient. There will be a blank in client.
要有耐心。客户端会有空白。
You can see it is doing building on backend(terminal will log it).
您可以看到它正在后台进行构建(终端将记录它)。
#2
15
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
.
如果你在Facebook的故障排除页面中推荐了lsof -n -i4TCP:8081,然后得到一个空结果,那么再试试使用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.
在我的例子中,McAfee杀毒软件正在运行在那个端口上监听的进程。杀死那个过程(我知道,我知道!)解决了这个问题。
#3
12
Try the following steps for those that need to change port 8081 to a different port.
对于需要将端口8081更改为另一个端口的操作,请尝试以下步骤。
> npm start
> npm开始
will launch node_modules/react-native/packager/packager.sh
将启动node_modules / react-native /包装机/ packager.sh吗
In there it will merge command line parameters, i.e. --port into the predefined options. i.e. port=8081
在那里,它将合并命令行参数,即端口进入预定义选项。即端口= 8081
I updated the package.json start
option to include my prefered port, as i was unable to stop existing services using this port.
我更新了包。json开始选项包括我的首选端口,因为我无法停止使用这个端口的现有服务。
{
"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
**注意,这可能不适用于android,这显然是硬编码到8081栈的帖子。
Building XCode When building xcode 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.
在构建XCode时,构建XCode仍然会失败,因为它试图运行一个脚本以启动节点。您将需要从构建过程中删除该脚本,或者将其更新到新的端口。
Under libraries
select React.xcodeproj
. In the main screen select Build Phases
. You will see Run Script
.
在库选择React.xcodeproj。在主屏幕中选择构建阶段。您将看到运行脚本。
Either remove this entry, having called npm start yourself, or edit the port.
要么删除该条目,调用npm启动自己,要么编辑端口。
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
调试似乎是8081遍了整个商店。需要另外更新RCTWebSocketExecutor。/ RCTWebSocket.xcodeproj m在xcode项目:库
- (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.
**如果只在IOS中启动,那么你还需要编辑launchpackager .命令来添加适当的端口,因为xcode使用这个文件来运行javascript。
$THIS_DIR/packager.sh --port=8999
#4
5
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 custom port. Have to take over the 8081
port from McAfee
.
对于Android,我可以使用adb来重定向端口,但在iOS中,我们无法找到在定制端口上运行响应的方法。必须接管McAfee的8081端口。
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.
对于那些无法直接杀死McAfee进程/服务的Mac用户,您可以通过launchctl(MacOS)卸载它,然后您可以在默认的8081端口上运行packager服务器。
cd /Library/LaunchDaemons
sudo launchctl unload com.mcafee.agent.macmn.plist
Also wrote an memo to explain the launchctl detail and MacOS boot flow.
还写了一个备忘录来解释launchctl细节和MacOS引导流。
#5
1
Interesting enough, I just run into the same problem. However the solution is a bit different for me, none of above suggested methods worked.
有趣的是,我遇到了同样的问题。但是,对于我来说,解决方案有点不同,上面没有一个建议的方法有效。
I have LittleSnithc installed, and when I hit run in Xcode, LittleSnitch prompted that Xcode was trying to connect to "localhost.lan" via nc. Of course I had no reason to deny it, then the build failed.
我安装了LittleSnithc,当我在Xcode中运行时,LittleSnitch提示Xcode尝试连接到“localhost”。通过数控局域网”。当然,我没有理由否认它,然后就失败了。
All I did after is denying the outgoing connection of Xcode via nc to localhost.lan in LittleSnitch and the probleme is gone!
我所做的就是拒绝通过nc到localhost来连接Xcode。lan在LittleSnitch,问题已经消失了!
#6
1
I figured out the issue: for some reason I didn't kill the process on port 8081
and it was causing Xcode to fail.
我发现了这个问题:出于某种原因,我没有在端口8081上杀死这个进程,它导致Xcode失败。
Solution:
解决方案:
- Kill the process on
port 8081
. - 在端口8081上杀死进程。
- Clean Xcode:
Xcode Menu > Product > Clean
. - 清洁Xcode: Xcode菜单>产品> Clean。
- Reopen Xcode.
- Xcode重新开放。
Resource:
资源:
React-Native故障排除
#7
0
My problem was the Wifi DNS setup..
我的问题是Wifi DNS设置。
i. Go to Settings-> Network.
进入设置->网络。
ii. Select the connected Wifi, click Advance.
二世。选择连接的Wifi,点击前进。
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.
三世。选择DNS,您可能将您的DNS服务器设置为8.8.8.8(上帝知道您的意图)。删除它并将其设置为默认的192.168.1.1。单击OK。
iv. Run the react-native run-ios in terminal and it works.
4 .在终端运行堆内运行的Run -ios,运行正常。
#8
0
run the following command:
运行以下命令:
react-native start --port=8088
react-native开始——端口= 8088
I had the same issue with McAfee running on 8081. This worked for me.
我和迈克菲在8081年也有同样的问题。这为我工作。
https://facebook.github.io/react-native/docs/troubleshooting.html
https://facebook.github.io/react-native/docs/troubleshooting.html
#1
4
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.
在别人的帮助下。我尝试了以下步骤。这对我和其他人都有帮助。它只适用于iOS。假设我们想将8081端口更改为8999端口。
First, Open Xcode.
首先,打开Xcode。
-
Look at Project navigator(left) In [ProjectName]/[ProjectName]/AppDelegate.m:
在[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.
点击“React.xcodeproj”。在主面板上,点击“构建阶段”标签。
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
在项目导航器(左)[ProjectName] /库/ RCTWebSocket中。xcodeproj / RCTWebSocketExecutor。m:搜索8081,用8999替换。
Second open Finder
第二个开放仪
In the project root, open “package.json” :
在项目根中打开“包”。json”:
Change the “script” attribute to :
将“脚本”属性更改为:
{...
"start": "node_modules/react-native/packager/packager.sh --port=8999"
...
}
Then Open terminal
然后打开终端
-
$cd to project root :
$cd至项目根:
$ npm start
美元npm开始
Cool! Then
太酷了!然后
Go back to Xcode and click play button.
回到Xcode,点击play按钮。
Cross your fingers.
交叉你的手指。
Be Patient. There will be a blank in client.
要有耐心。客户端会有空白。
You can see it is doing building on backend(terminal will log it).
您可以看到它正在后台进行构建(终端将记录它)。
#2
15
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
.
如果你在Facebook的故障排除页面中推荐了lsof -n -i4TCP:8081,然后得到一个空结果,那么再试试使用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.
在我的例子中,McAfee杀毒软件正在运行在那个端口上监听的进程。杀死那个过程(我知道,我知道!)解决了这个问题。
#3
12
Try the following steps for those that need to change port 8081 to a different port.
对于需要将端口8081更改为另一个端口的操作,请尝试以下步骤。
> npm start
> npm开始
will launch node_modules/react-native/packager/packager.sh
将启动node_modules / react-native /包装机/ packager.sh吗
In there it will merge command line parameters, i.e. --port into the predefined options. i.e. port=8081
在那里,它将合并命令行参数,即端口进入预定义选项。即端口= 8081
I updated the package.json start
option to include my prefered port, as i was unable to stop existing services using this port.
我更新了包。json开始选项包括我的首选端口,因为我无法停止使用这个端口的现有服务。
{
"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
**注意,这可能不适用于android,这显然是硬编码到8081栈的帖子。
Building XCode When building xcode 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.
在构建XCode时,构建XCode仍然会失败,因为它试图运行一个脚本以启动节点。您将需要从构建过程中删除该脚本,或者将其更新到新的端口。
Under libraries
select React.xcodeproj
. In the main screen select Build Phases
. You will see Run Script
.
在库选择React.xcodeproj。在主屏幕中选择构建阶段。您将看到运行脚本。
Either remove this entry, having called npm start yourself, or edit the port.
要么删除该条目,调用npm启动自己,要么编辑端口。
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
调试似乎是8081遍了整个商店。需要另外更新RCTWebSocketExecutor。/ RCTWebSocket.xcodeproj m在xcode项目:库
- (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.
**如果只在IOS中启动,那么你还需要编辑launchpackager .命令来添加适当的端口,因为xcode使用这个文件来运行javascript。
$THIS_DIR/packager.sh --port=8999
#4
5
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 custom port. Have to take over the 8081
port from McAfee
.
对于Android,我可以使用adb来重定向端口,但在iOS中,我们无法找到在定制端口上运行响应的方法。必须接管McAfee的8081端口。
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.
对于那些无法直接杀死McAfee进程/服务的Mac用户,您可以通过launchctl(MacOS)卸载它,然后您可以在默认的8081端口上运行packager服务器。
cd /Library/LaunchDaemons
sudo launchctl unload com.mcafee.agent.macmn.plist
Also wrote an memo to explain the launchctl detail and MacOS boot flow.
还写了一个备忘录来解释launchctl细节和MacOS引导流。
#5
1
Interesting enough, I just run into the same problem. However the solution is a bit different for me, none of above suggested methods worked.
有趣的是,我遇到了同样的问题。但是,对于我来说,解决方案有点不同,上面没有一个建议的方法有效。
I have LittleSnithc installed, and when I hit run in Xcode, LittleSnitch prompted that Xcode was trying to connect to "localhost.lan" via nc. Of course I had no reason to deny it, then the build failed.
我安装了LittleSnithc,当我在Xcode中运行时,LittleSnitch提示Xcode尝试连接到“localhost”。通过数控局域网”。当然,我没有理由否认它,然后就失败了。
All I did after is denying the outgoing connection of Xcode via nc to localhost.lan in LittleSnitch and the probleme is gone!
我所做的就是拒绝通过nc到localhost来连接Xcode。lan在LittleSnitch,问题已经消失了!
#6
1
I figured out the issue: for some reason I didn't kill the process on port 8081
and it was causing Xcode to fail.
我发现了这个问题:出于某种原因,我没有在端口8081上杀死这个进程,它导致Xcode失败。
Solution:
解决方案:
- Kill the process on
port 8081
. - 在端口8081上杀死进程。
- Clean Xcode:
Xcode Menu > Product > Clean
. - 清洁Xcode: Xcode菜单>产品> Clean。
- Reopen Xcode.
- Xcode重新开放。
Resource:
资源:
React-Native故障排除
#7
0
My problem was the Wifi DNS setup..
我的问题是Wifi DNS设置。
i. Go to Settings-> Network.
进入设置->网络。
ii. Select the connected Wifi, click Advance.
二世。选择连接的Wifi,点击前进。
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.
三世。选择DNS,您可能将您的DNS服务器设置为8.8.8.8(上帝知道您的意图)。删除它并将其设置为默认的192.168.1.1。单击OK。
iv. Run the react-native run-ios in terminal and it works.
4 .在终端运行堆内运行的Run -ios,运行正常。
#8
0
run the following command:
运行以下命令:
react-native start --port=8088
react-native开始——端口= 8088
I had the same issue with McAfee running on 8081. This worked for me.
我和迈克菲在8081年也有同样的问题。这为我工作。
https://facebook.github.io/react-native/docs/troubleshooting.html
https://facebook.github.io/react-native/docs/troubleshooting.html