0
votes

I am trying to run a react native application in Android from Linux server, now I am getting this error when trying to start npm server with npm-start'.

> [email protected] start /home/lenovot430/Documents/ReactProjects/test0app
> node node_modules/react-native/local-cli/cli.js start

┌──────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│  Running Metro Bundler on port 8081.                                         │
│                                                                              │
│  Keep Metro running while developing on any JS projects. Feel free to        │
│  close this tab and run your own Metro instance if you prefer.               │
│                                                                              │
│  https://github.com/facebook/react-native                                    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::8081
    at Server.setupListenHandle [as _listen2] (net.js:1360:14)
    at listenInCluster (net.js:1401:12)
    at Server.listen (net.js:1485:7)
    at Promise (/home/lenovot430/Documents/ReactProjects/test0app/node_modules/metro/src/index.js:253:20)
    at new Promise (<anonymous>)
    at Object.<anonymous> (/home/lenovot430/Documents/ReactProjects/test0app/node_modules/metro/src/index.js:252:14)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/lenovot430/Documents/ReactProjects/test0app/node_modules/metro/src/index.js:46:24)
    at _next (/home/lenovot430/Documents/ReactProjects/test0app/node_modules/metro/src/index.js:66:9)
    at <anonymous>
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `node node_modules/react-native/local-cli/cli.js start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/lenovot430/.npm/_logs/2019-04-29T09_09_45_424Z-debug.log

If I try 'react-native run-android', app is stuck at loading screen.

The fixes I tried for fixing it

  1. Removed Node Modules, cleaned caches and installed again.

    rm -rf node_modules && npm cache clean --force && npm install

  2. Uninstalled and Reinstalled Watchman

    brew uninstall watchman brew link pcre brew install --HEAD watchman brew install watchman

  3. Cloned watchman repo and tried version 4.9.0

    $ git clone https://github.com/facebook/watchman.git $ cd watchman $ git checkout v4.9.0 # the latest stable release $ ./autogen.sh $ ./configure $ make $ sudo make install

I havent made any configuration changes in the react native app. I tried making a new project with react-native init, but in that project also, I am getting the same Error.

My package.json file

{
  "name": "test0app",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.8.3",
    "react-native": "0.59.5"
  },
  "devDependencies": {
    "@babel/core": "^7.4.4",
    "@babel/runtime": "^7.4.4",
    "babel-jest": "^24.7.1",
    "jest": "^24.7.1",
    "metro-react-native-babel-preset": "^0.53.1",
    "react-test-renderer": "16.8.3"
  },
  "jest": {
    "preset": "react-native"
  }
}
1
react-native run-android causing this error?Abdul Kawee
If I use react-native run-android, the app is stuck at Loading from Screen. npm-start is giving me this error.mad_greasemonkey
may be its because there is another program running on that port, check are there other command shells or program running through that portAbdul Kawee
That I had checked already. No service was running at that port. Look at the error, service started on the port, then it hit some error.mad_greasemonkey

1 Answers

0
votes

You have the error, Error: listen EADDRINUSE :::8081, which means "Address in use".

Sometimes the web server that is launched with the bundler fails to tear down properly, and thus it keeps port 8081 locked. You can find the rogue process using:

lsof -wni tcp:8081

And then kill it via its PID

kill -9 <PID>

I have to do this, once a fortnight or so.