Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the port 8081? #10715

Closed
codepandy opened this issue Nov 3, 2016 · 20 comments
Closed

How to change the port 8081? #10715

codepandy opened this issue Nov 3, 2016 · 20 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@codepandy
Copy link

Hi,

Because of the port is used by McAfee in my company,it's difficult to develop every time.

whether can the port be changed to another one?

how to do?

@ltwaia
Copy link

ltwaia commented Nov 3, 2016

There are two files needed to be modified about port 8081:

  1. react-native/local-cli/server/server.js - default
    2.react-native/React/React.xcodeproj/project.pbxproj - replace all 8081
    above two, it's ok;

@ummahusla
Copy link

What about react-native start --port 9988 ?

@hramos
Copy link
Contributor

hramos commented Nov 3, 2016

You'll need to start the packager on a different port using the --port flag, and also modify any files in the iOS/Android project that use the 8081 port. See #9145 for an on-going discussion. I'll go ahead and close this as duplicate.

@hramos hramos closed this as completed Nov 3, 2016
@codepandy
Copy link
Author

codepandy commented Nov 4, 2016

@hramos @ummahusla @ltwaia

  1. node_modules/react-native/local-cli/server/server.js
    2.node_modules/react-native/React/React.xcodeproj/project.pbxproj
    3.node_modules/react-native/React/Base/RCTBundleURLProvider.m
    4.node_modules/react-native/Libraries/WebSocket/RCTWebSocketExecutor.m
    5.node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/AndroidInfoHelpers.java
    6.react-native/packager/react-packager/src/Server/tests/Server-test.js
    7.react-native/local-cli/util/isPackagerRunning.js
    8.react-native/Libraries/Image/tests/resolveAssetSource-test.js

I modified all of the files listed above,the packager could be started,but when I ran the command "react-native run-android",it didn't still worked.
there was a error:

Could not run adb reverse:Command failed: C:\users\jack\AppData\Local\Android\sdk/platform-tools/adb -s 029ds34d reverse tcp:8081 tcp:8081

@Aaronius
Copy link

@codepandy I replaced EVERY 8081 I could find in my project with 8088 which seemed to work.

@liuxh0
Copy link

liuxh0 commented Feb 15, 2017

My 8081 port is also occupied by McAfee. Combining the answer of @ltwaia and @Aaronius, it finally worked for me!

@falbertp
Copy link

falbertp commented Mar 9, 2017

Got the same problem here on Genymotion, android studio emulator and real devices. Isn't there any elegant alternative rather than need to change every files to another port other than 8081?

@themnd
Copy link

themnd commented May 10, 2017

our server component bind on port 8081, running the react-native client on the same machine is cumbersome...

@ghost
Copy link

ghost commented Jul 6, 2017

Changed EVERY instance of port from 8081 to something else... then deleted the .babelrc file at the root of the app directory... ran again and it works. That was way too difficult. This crap needs to be fixed. Just spent 4 hours trying to figure out a solution.

@hramos
Copy link
Contributor

hramos commented Jul 21, 2017

Duplicate of #9145

@hramos hramos marked this as a duplicate of #9145 Jul 21, 2017
facebook-github-bot pushed a commit that referenced this issue Aug 17, 2017
Summary:
Thanks for submitting a PR! Please read these instructions carefully:

- [x ] Explain the **motivation** for making this change.
- [x ] Provide a **test plan** demonstrating that the code is solid.
- [x ] Match the **code formatting** of the rest of the codebase.
- [x ] Target the `master` branch, NOT a "stable" branch.

The section on changing ports is missing a key step for folks wishing to run on device

What existing problem does the pull request solve?

Changing packager port to something other than 8081 also requires the react native xcode project file to be updated in order to be able to build and run on device. The section on changing ports currently does not address this. See #10715 (comment).

Documentation update, no tests required.

A good test plan has the exact commands you ran and their output, provides screenshots or videos if the pull request changes UI or updates the website. See [What is a Test Plan?][1] to learn more.

If you have added code that should be tested, add tests.

Sign the [CLA][2], if you haven't already.

Small pull requests are much easier to review and more likely to get merged. Make sure the PR does only one thing, otherwise please split it.

Make sure all **tests pass** on both [Travis][3] and [Circle CI][4]. PRs that break tests are unlikely to be merged.

For more info, see the ["Pull Requests"][5] section of our "Contributing" guidelines.

[1]: https://medium.com/martinkonicek/what-is-a-test-plan-8bfc840ec171#.y9lcuqqi9
[2]: https://code.facebook.com/cla
[3]: https://travis-ci.org/facebook/react-native
[4]: http://circleci.com/gh/facebook/react-native
[5]: https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests
Closes #14293

Differential Revision: D5647393

Pulled By: hramos

fbshipit-source-id: 040c3edea7d25c0efe560d5df30e86e1f26355bc
@juliantellez
Copy link

@codepandy @liuxh0 I just ran into the same problem, thanks McAfee 👎
this is how I stopped the macmn process

sudo lsof -n -i4TCP:8081 # get the process' PID
sudo launchctl list | grep 5693 # find the launchd endpoint
sudo launchctl remove com.mcafee.agent.macmn 

@Qvatra
Copy link

Qvatra commented Oct 17, 2017

same problem here.

@swap7206
Copy link

swap7206 commented Nov 2, 2017

Same problem , trying it on windows

@aelshamy
Copy link

npm start -- --port=8080 worked for me

@pranavdixit
Copy link

Two Steps which worked for me:

  1. node_modules/react-native/local-cli/server/server.js
    change "default: 8081, " to "default: 1234,"
  2. On android emulator press cmd +m(for mac)
    Dev Settings > Debug server host & port for device >"10.0.2.2:1234"

@noumantahir
Copy link

These are the files where I had to tweak port number to make it work on a different port

  1. node_modules/react-native/local-cli/server/server.js
  2. XCode -> [App]/Libraries/React.xcodeproj/React/Base/RCTBundleURLProvider.m
  3. XCode -> [App]/Libraries/React.xcodeproj/React/Base/RCTBridgeDelegate.m
  4. XCode -> [App]/Libraries/React.xcodeproj/React/DevSupport/RCTInspectorDevServerHelper.mm
  5. XCode -> [App]/Libraries/RCTWebSocket.xcodeproj/RCTWebSocketExecutor.m

Afterwards, running simple react-native run-ios without specifying any extra argument ran the package and app on my selected port. I am using "react-native": "0.52.0"

@amarnathpatel
Copy link

Two Steps which worked for me:

node_modules/react-native/local-cli/server/server.js
change "default: 8081, " to "default: 8088,"
On android emulator press cmd +m(for mac)
Dev Settings > Debug server host & port for device >"10.0.2.2:8088"

@amarnathpatel
Copy link

amarnathpatel commented Feb 19, 2018

For debugging(Windows) , open the react native debugger -
http://localhost:8088/debugger-ui

Then press Ctrl +Shift + J , this will open Developer Tools where you can use tabs like Console, Source etc.

@Louies89
Copy link

Louies89 commented Feb 19, 2018

Hi All,
I found the same issue while running in windows environment and simulating using android simulator.
After doing some trial & error, I found the solution as below:

1>> Change the port in "\node_modules\react-native\local-cli\server\server.js" from default:

process.env.RCT_METRO_PORT || 8081

to

default: process.env.RCT_METRO_PORT || 9088

if the port is blocked or issued to some other application.
Note: You can choose any port number, I have chosen 9088
2>> Run the command react-native run-android --port 9088 (Put your port number here). This port shall be sent to adb running, so that both server and adb shall be in same port.
3>> Now in Android studio simulator, press Ctrl+m, to go for "Dev Setting", then select Debug Server port & host for Device, set "localhost:9088".
4>> Open developer console in chrome using the url http://localhost:9088/debugger-ui/

Now it will start loading the changes you make in your application.

Enjoy coding now :)

@FisherEat
Copy link

8081端口被占用,我是用这种方式实现的

  1. react-native/local-cli/server/server.js - default

  2. react-native/React/React.xcodeproj/project.pbxproj - replace all "port" 8081 ,not fileref

  3. above two, it still cannot run . So you should search global in you native project in Xcode ,change all

  4. @ltwaia

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests