React Native run-ios by simulator error:Port 8081 already in use - react-native

React Native version: last 0.60
When I terminal react-native run-ios, first time successed!
But after all failed.
Open the Xcode xcworkspace tips:
Connection to localhost port 8081 [tcp/sunproxyadmin] succeeded!
Port 8081 already in use, packager is either not running or not running correctly
Command PhaseScriptExecution failed with a nonzero exit code
PS: sudo lsof -i tcp:8081 can not find the PID, so no kill.
How to find the port number 8081 or some other actions to build.

Related

React native terminal, how to get the process id of new terminal window launched by `react-native start`?

When I run a command like react-native run-ios or react-native start, it launches a new terminal window with the react native compiling process running/watching inside of the new terminal window.
How can I watch for this new process to start? Or find it among running terminal processes? Find the pid, etc.
My task is specific and obscure, but this is more or less exactly what I need to do. Can anyone help?
Checking which PID is used for the port of your react native application should suffice. The standard port for the react-native-cli when running react-native run-ios or react-native start is 8081. For expo it is 19000.
For specifying a custom port (e.g. 9988) use
react-native start --port 9988
When your react native application is running, then you can check the corresponding PID in usage for that port (sudo might be needed at the beginning of the command)
lsof -i -P | grep LISTEN | grep 8081
node 38273 [USER] 31u IPv6 0x2207bcb724ddd40d 0t0 TCP *:8081 (LISTEN)
In this example, the corresponding PID is 38273

I have some problems to make react-native work on a physical device with expo app

screenshot of terminal
I'm using MacBook Air M1.
To make react-native work on a physical device with expo application, I wrote these codes:
npm install -g expo-cli
npx expo-cli init cars
cd cars
npm start
But it doesn't work, I'm looking forward your replies thank you.
Try to run expo start and make sure that port 8081 not used by any other server. Because in given screenshot it looks your port 8081 is already been used and on top of that you trying to run expo project thats why always failing.
I think your previous process is still running, try to stop those process and then start expo server again
Do this to stop the process:
Run this command for getting PID of the process running in your port 8081
lsof -i tcp:8081
Note the PID from the table which is shown after that command
Run this command to kill your process kill -9 {PID}.
kill -9 3421
You have to add your PID in place of 3421 that I used.
I Hope that it helps..

React Native Development Server closed automatically after successful build

I am new to ReactNative. I have installed react-native in my Ubuntu(18.04). I am trying to run the basic app after installation using CLI.
I am trying to make the build in android using sudo react-native run-android after successful build server closed automatically. It means that I have to run the command every time after making change.
Development Server closed automatically.
Please find the screenshot.
Development Server Closed
This error is coming because some process is already running on 8081 port. Stop that process and then run your command, it will run your code. For this first list all the process which are using this port by typing
$ adb reconnect
This is not necessary in most cases, but just in case, let's reset your connection with your mobile and restart adb server. Finally:
$ adb reverse tcp:8081 tcp:8081
Then run this command
lsof -i :8081
You will get a Process id which is using port 8081 Now kill the process
$ sudo kill -9 <PID>
Then run the project
react-native run-android
I faced same issues.
I solved the issues by changing node version from 13.3.0 to node version 10.18.0.

Could not connect to development server on android emulator

When i run a react native simple app using command.react-native run-android.Then i got an error "could not connect to a development server, although my packager is also run.
There is a few things you can try to solve this.
From the React Native official docs (https://facebook.github.io/react-native/docs/troubleshooting) you could try to "terminate the process on port 8081" by running:
$ sudo lsof -i :8081
$ kill -9 <PID>
You will run the second command on all PIDs that are using port 8081 (this will terminate your emulator too).
Then, restart the emulator and in one terminal, run:
$ npm start
and on a second terminal:
$ react-native run-android
Hope this can help!
Starting with Android 9.0 (API level 28), cleartext support is disabled by default.
https://stackoverflow.com/a/53158627/1490685

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.
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
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",
}
Runing React Native Apps on Mac OS when port 8081 is already in use due to another service or APP
For ios emulator
Open Xcode and navigate to Pods -> Development Pods -> React-Core -> Default -> Base -> RCTDefines
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)
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
Just Runs npx react-native run-android --port=8088 (or desired port #) from the project folder