Impossible to execute my firebase functions locally

Viewed 881

I am trying to run firebase cloud functions emulator in my local environment but I get a EADDRINUSE issue.

  1. I can successfully run firebase emulator :

✔ functions[main]: http function initialized (http://localhost:5001/firebaseapp/main).

┌───────────────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! View status and logs at http://localhost:4000 │
└───────────────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
└───────────┴────────────────┴─────────────────────────────────┘
  Other reserved ports: 4400, 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
 
>  Server Started
>  Connected to MongoDB
  1. However, after that things don't go as expected, when I use the link provided by the emulator :

http://localhost:5001/firebaseapp/main

to make my test request :

http://localhost:5001/firebaseapp/main/test

I get the following error :

>  events.js:288
>        throw er; // Unhandled 'error' event
>        ^
>  
>  Error: listen EADDRINUSE: address already in use :::5000
>      at Server.setupListenHandle [as _listen2] (net.js:1309:16)
>      at listenInCluster (net.js:1357:12)
>      at Server.listen (net.js:1445:7)
>      at Function.listen (/Users/Desktop/fb_tour/functions/node_modules/express/lib/application.js:618:24)
>      at Object.<anonymous> (/Users/Desktop/fb_tour/functions/index.js:61:5)
>      at Module._compile (internal/modules/cjs/loader.js:1158:30)
>      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
>      at Module.load (internal/modules/cjs/loader.js:1002:32)
>      at Function.Module._load (internal/modules/cjs/loader.js:901:14)
>      at Module.require (internal/modules/cjs/loader.js:1044:19)
>      at require (internal/modules/cjs/helpers.js:77:18)
>      at /usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:681:33
>      at Generator.next (<anonymous>)
>      at fulfilled (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:5:58)
>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  Emitted 'error' event on Server instance at:
>      at emitErrorNT (net.js:1336:8)
>      at processTicksAndRejections (internal/process/task_queues.js:84:21) {
>    code: 'EADDRINUSE',
>    errno: 'EADDRINUSE',
>    syscall: 'listen',
>    address: '::',
>    port: 5000
>  }

I tried to kill the port 5000 but apparently there is no active PID process so I couldn't get the PID. I also restarted my computer to force every process to shut down but this error still persist.

Any suggestion ?

EDIT : I got the same issue even when I change the listen port in my nodejs app. For e.g. when I set port 3000 I get the same error message telling that the port 3000 is already in use.

EDIT 2 : I think I have identified the cause of the issue. I have this warning message when I run the functions emulator

It seems that you are running multiple instances of the emulator suite for project firebaseapp. This may result in unexpected behavior.

I think there are two instances of my app running at the same time, causing this error. However I have no Idea about how to fix this.

2 Answers

if you have app.listen() in your function code then remove it and everything should work fine.

For the last update you provided, the error message was reported on github I think you can follow the suggestions there in order to avoid the issue.

It seems like you only need to CTRL-C command before to use the emulator. According to this link, the issue has been solved.

Related