Firebase serve error: Port 5000 is not open. Could not start functions emulator

JavascriptFirebaseFirebase Tools

Javascript Problem Overview


I'm trying to serve firebase functions locally, but when I run firebase serve or firebase emulators:start the error message is: "Port 5000 is not open, could not start functions emulator."

I'm using Windows 10, so I've tried to change the port number, check if the port is blocked by Firewall and I create a new rule in Firewall to ports 5000-5010 but none of this approaches worked for me.

Javascript Solutions


Solution 1 - Javascript

For Mac/Linux, use the Terminal/Shell to find the Process ID (PID), then kill the process.

sudo lsof -i :5000
sudo kill -9 PID

Solution 2 - Javascript

In MacOS Monterey, port 5000 may be claimed by a new "AirPlay Receiver". This can be disabled in Settings -> Sharing:

Screenshot of settings panel for disabling AirPlay Receiver

Disabling the AirPlay Receiver (if you do not need it) frees up port 5000.

Solution 3 - Javascript

Alternatively use a different port, it is a simple solution.

firebase serve -p 5001

Solution 4 - Javascript

For Windows Users:

netstat -ano|findstr "PID :5000"

And then with the Process ID (PID) found at the end of the line.

taskkill /pid FOUNDPID /F

Command taskkill does not work from within terminal of VS Code context. It needs an (elevated) CMD-prompt or equivalent Powershell environment in order to successfully terminate the listening on 127.0.0.1:5000.

Solution 5 - Javascript

The thing here is your port No 5000 is running with some process. So, first, you need to kill that process.

To find the Process id in ubuntu

sudo lsof -i :5000

Suppose PID you get 14541

To kill the Process

sudo kill -9 14541

Solution 6 - Javascript

lsof -t -i tcp:5000 | xargs kill

A one-line alternative for Mac users that pipes the the process ID directly to kill. h/t @manav

Original question was for Windows, but might be useful for others as question is now ranked highly in search results.

Solution 7 - Javascript

Port 5000 and 7000 are taken by airplay on MacOS Monterey.

Switch off Airplay Receiver as suggested here or

update firebase.json with a different port

"emulators": {
   
    "hosting": {
      "port": 5004
    }
}

Solution 8 - Javascript

A similiar problem has recently been reported in the official github repo: https://github.com/firebase/firebase-tools/issues/1606.

It is caused by a bug in a dependency (node portfinder), as you can see here. https://github.com/http-party/node-portfinder/pull/86

A quick fix to edit it might be to use the old version of node portfinder (v 1.0.21). Alternatively, you can do it by editing node_modules/firebase-tools/lib/emulator/controller.js and changing yield pf.getPortPromise({ port, stopPort: port }) to yield pf.getPortPromise({ port, stopPort: port + 1 }).

EDIT: As suggested by Mladen Skrbic, in order to find the firebase-tools folder, you should run npm root -g and find the firebase-tools folder in there.

This should fix the issue!

Solution 9 - Javascript

This worked for me.

Just restart your system.

Solution 10 - Javascript

just run command firebase serve --only functions --host 0.0.0.0

Solution 11 - Javascript

Running this command did the trick for me: firebase emulators:start --only firestore

also close this window: cmd window to close

Solution 12 - Javascript

Instead of latest firebase-functions(which is 3.2.0 currently), forcing it to stay at 3.0.2 solved in my case.

"dependencies": {
    "firebase-admin": "^8.2.0",
    "firebase-functions": "3.0.2",
    ...
}

(Also I am using firebase-tools version 7.0.2 atm, didnt check it with latest. If it doesnt work try reverting firebase-tools to 7.0.2)

Solution 13 - Javascript

A quick fix npm i -g [email protected]

Solution 14 - Javascript

macOS Monterey 12.2 user here. I've simply changed the port to 5005 and it worked like a charm.

{
  "hosting": {
    "public": "functions/browser",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "ssrapp"
      }
    ]
  },
  "emulators": {
    "hosting": {
      "port": "5005"
    }
  }
}

Solution 15 - Javascript

where is? node_modules/firebase-tools/lib/emulator/controller.js I cannot find "firebase-tools" folder in node_modules. I able to find only firebase-funstions and firebase-admin.

Solution 16 - Javascript

SOLUTION TO: Firebase serve error: Port 5000 is not open. Could not start functions emulator

If you get one of the following error messages when you run Firebase, you can easily resolve the problem by switching to another version of Firebase tools.

Port 5000 is not open, could not start functions emulator.

If you are using version 6 of Firebase Tools, you might switch to latest version (6.12.0), or you might try v7.2.2. To change to Firebase Tools version run to following node package manager command.

npm install -g [email protected]

Solution 17 - Javascript

Try this way:

firebase serve --only functions -p 5002

Solution 18 - Javascript

If firebase serve --host 127.0.0.1 solves it for you; maybe you haven't set up your hosts file. Linux - Network configuration

Solution 19 - Javascript

I faced the same issue not quite long ago.

I found out I had firebase running on another terminal onmy computer.

So before you try firebase serve, check if it running on another terminal.

I hope it solves your problem just like mine.

Solution 20 - Javascript

first, close all tab restart VS code then just go in firebase.json file then change ui port number then start again, it will work!

"ui": { "enabled": true, "port": "enter any number" }

Solution 21 - Javascript

As suggested here https://github.com/firebase/firebase-tools/issues/2856#issuecomment-902411134

Upgrading Node.js is working.

>I just upgraded Node to 14.17.5. This solves the problem. I just press Ctrl+C to stop all emulators.

Solution 22 - Javascript

close everything, delete your "prefetch" and "%temp%" in "run" option and restart your PC. that worked for me

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVictor de AlmeidaView Question on Stackoverflow
Solution 1 - JavascriptpublicmatView Answer on Stackoverflow
Solution 2 - JavascriptErikWitternView Answer on Stackoverflow
Solution 3 - JavascriptElaView Answer on Stackoverflow
Solution 4 - JavascriptNestor SolalindeView Answer on Stackoverflow
Solution 5 - Javascriptalok kumarView Answer on Stackoverflow
Solution 6 - JavascriptwarfieldView Answer on Stackoverflow
Solution 7 - JavascriptVenkat KotraView Answer on Stackoverflow
Solution 8 - JavascriptWendigoView Answer on Stackoverflow
Solution 9 - Javascriptbiggest_boyView Answer on Stackoverflow
Solution 10 - JavascriptGeetanshu GulatiView Answer on Stackoverflow
Solution 11 - JavascriptItay TurView Answer on Stackoverflow
Solution 12 - JavascriptMertcan ÇüçenView Answer on Stackoverflow
Solution 13 - JavascriptjDevView Answer on Stackoverflow
Solution 14 - JavascriptTiberiu OpreaView Answer on Stackoverflow
Solution 15 - JavascriptmeltedmoonView Answer on Stackoverflow
Solution 16 - JavascriptChidi-NwanetoView Answer on Stackoverflow
Solution 17 - JavascriptDam Van DuongView Answer on Stackoverflow
Solution 18 - JavascriptmedoView Answer on Stackoverflow
Solution 19 - JavascriptJay StanceView Answer on Stackoverflow
Solution 20 - JavascriptSanjeev GuptaView Answer on Stackoverflow
Solution 21 - JavascriptpreetkView Answer on Stackoverflow
Solution 22 - JavascriptA K M ALI HASANView Answer on Stackoverflow