React Native Development Server closed automatically after successful build - react-native

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.

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 run-ios by simulator error:Port 8081 already in use

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.

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

React native stuck at loading from localhost : 8081 on physical device using USB debugger

When I run react-native run-android it builds successfully and there after
Mobile screen shows nothing more than loading from local host : 8081
I have tried adb reverse tcp:8081 tcp:8081
Start by closing the App on your phone and clearing phone memory.
Close metro bundler on your PC.
Then clear npm cache as follows: npm cache clean --force
Then clean up gradle as follows:
Change into android directory in your project folder: cd android
To clean clean gradle simply run: ./gradlew clean
cd .. back into your project's root directory.
Build your app again using whichever method suits you. My preferred method for RN apps without expo on a windows machine is as follows:
npx react-native run-android
Try either of these ways to fix it:
Try to Open Developer menu by press Ctrl + M in emulator and choose the Setting port, then input the value localhost:8081.
Try to connect the other wifi, then run 'adb reverse tcp:8081 tcp:8081'
Try to change the URL on chrome to http://localhost:8081/debugger-ui/
Cheer!
Samsung DeX!
Samsung DeX runs in the background to discover device connections, it uses port 8081. In my case, it interfered with Metro and adb reverse. Exiting the system tray app fixed the entire issue.
For some reason it was a watchman issue. I remember installing watchman a few days before and it was causing the issue. I uninstalled watchman and it worked.
Uninstalling watchman made it work for me.