user3552178
user3552178

Reputation: 2971

port 8081 already in use when "react-native run-ios"

Yes i have read this but still don't know how to make it work. react native - Port 8081 already in use, packager is either not running or not running correctly Command /bin/sh failed with exit code 2

Originally i was doing this

1. react-native init Hello
2. react-native run-ios

Then hit this "port 8081 already in use".

Did read the react doc, https://facebook.github.io/react-native/docs/troubleshooting.html

1. cannot kill the process using 8081, it keeps on coming back,
   and i don't want to kill it
2. react-native start --port=8088
3. update node_modules/react-
native/React/React.xcodeproj/project.pbxproj file. Did it.

Where and which step should i run "react-native start --port=8088" ?

btw, i'm an average engineer, but if i cannot run the very 1st react-native sample in 2 hours, i just cannot see how it can fly, this is very annoying.

Upvotes: 4

Views: 9173

Answers (3)

AndrewDev
AndrewDev

Reputation: 51

Runing React Native Apps on Mac OS when port 8081 is already in use due to another service or APP

For ios emulator

  1. Open Xcode and navigate to Pods -> Development Pods -> React-Core -> Default -> Base -> RCTDefines
  2. Change #define RCT_METRO_PORT 8081 => #define RCT_METRO_PORT 8088 or to desired port number (make sure to change all ocurrencies on that file)
  3. Run npx react-native run-ios --port 8088 (or desired port number and needs to match with the one on RCTDefines file) from the project folder

For Android

  1. Just Runs npx react-native run-android --port=8088 (or desired port #) from the project folder

Upvotes: 2

Alex Aymkin
Alex Aymkin

Reputation: 518

In yarn managed project in package.json

 "scripts": {
      ...
    "ios": "npx react-native run-ios --port 19001 && npx react-native start --port 19001",
    "android": "npx react-native run-android --port 19001 && npx react-native start --port 19001",
    }

Upvotes: 1

jcollum
jcollum

Reputation: 46579

In RN 0.55 you can fix this with:

react-native start --port=1234

and then in a different window:

react-native run-ios --port 1234

Versions:

✗ react-native --version
react-native-cli: 2.0.1
react-native: 0.55.4

Upvotes: 9

Related Questions