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

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.



Solution 1:[1]

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:[2]

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:[3]

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

firebase serve -p 5001

Solution 4:[4]

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:[5]

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:[6]

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:[7]

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:[8]

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:[9]

This worked for me.

Just restart your system.

Solution 10:[10]

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

Solution 11:[11]

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

also close this window: cmd window to close

Solution 12:[12]

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:[13]

A quick fix npm i -g [email protected]

Solution 14:[14]

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:[15]

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:[16]

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:[17]

Try this way:

firebase serve --only functions -p 5002

Solution 18:[18]

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:[19]

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:[20]

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:[21]

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:[22]

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