80

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.

Victor de Almeida
  • 990
  • 2
  • 7
  • 7
  • 1
    Have the same problem, on MacOS. Reverted to firebase-tools version 6.12.0 for now and that seems to work (although not a real solution to the problem). `npm i -g firebase-tools@6.12.0` – Iggy van Lith Aug 17 '19 at 16:05
  • using firebase-tools@6.12.0 generated grpc related error in node module, the latest firebase-tools doesn't have this error. => reverting back to v6.12.0 did not work for me :( – Thr3e Aug 17 '19 at 17:44
  • 1
    @Thr3e This happened to me, too. So, I installed the grpc module in functions folder and it worked again – Victor de Almeida Aug 18 '19 at 18:57
  • In my case, I had `AirServer` running, which was using the `5001` port. So I closed it once I saw `publicmat`'s answer. – Ben Butterworth Aug 04 '21 at 13:18

24 Answers24

62

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
publicmat
  • 781
  • 5
  • 6
  • 27
    `lsof -t -i tcp:5000 | xargs kill` - one line alternative that pipes the output of lsof to kill (h/t [@manav](https://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac/3855359#3855359)) – warfield Aug 11 '20 at 18:02
  • 27
    If you are using macOS Monterey, the Airplay server now uses Port 5000 so you either need to change the port for your process or kill Airplay receiver in System Preferences > Sharing – Clive Townsend Nov 19 '21 at 15:50
  • 1
    @warfield lsof -t -i tcp:5000 | xargs kill didn't help :( – Liker777 Apr 23 '22 at 04:52
60

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.

ErikWittern
  • 1,083
  • 9
  • 13
42

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

firebase serve -p 5001
Gerry
  • 1,159
  • 1
  • 14
  • 29
Ela
  • 429
  • 4
  • 3
21

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.

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
Nestor Solalinde
  • 563
  • 4
  • 15
15

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
    }
}
Venkat Kotra
  • 10,413
  • 3
  • 49
  • 53
14

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

Find process id in Ubuntu

sudo lsof -i :5000

Suppose you get PID 14541

Kill the process

sudo kill -9 14541
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
alok kumar
  • 317
  • 3
  • 11
13
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.

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
warfield
  • 624
  • 6
  • 14
4

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!

Wendigo
  • 444
  • 1
  • 7
  • 18
4

This worked for me.

Just restart your system.

biggest_boy
  • 381
  • 4
  • 23
4

just run command

firebase serve --only functions --host 0.0.0.0
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Geetanshu Gulati
  • 692
  • 8
  • 13
3

Running this command did the trick for me:

firebase emulators:start --only firestore

also close this window: cmd window to close

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Itay Tur
  • 683
  • 1
  • 15
  • 40
3

Try this way:

firebase serve --only functions -p 5002
Syscall
  • 19,327
  • 10
  • 37
  • 52
2

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)

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Mertcan Çüçen
  • 466
  • 3
  • 13
2

A quick fix

npm i -g firebase-tools@7.8.0
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
jDev
  • 21
  • 4
2

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"
    }
  }
}
Tiberiu Oprea
  • 153
  • 1
  • 3
  • 7
1

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.

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 firebase-tools@6.12.0
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Chidi-Nwaneto
  • 634
  • 7
  • 11
0

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

medo
  • 66
  • 6
0

I faced the same issue not quite long ago.

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

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

I hope it solves your problem just like mine.

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Jay Stance
  • 11
  • 2
0

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"
    }
Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 18 '21 at 17:39
0

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.

karel
  • 5,489
  • 46
  • 45
  • 50
preetk
  • 189
  • 4
  • 12
0

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

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 05 '22 at 05:39
0
{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "source": "functions"
  },
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "functions": {
      "port": 5001
    },
    "firestore": {
      "port": 8080
    },
    "hosting": {
      "port": 5005
    }
  }
}

I'm using macOS Monterey 12.6 , I just changed the hosting port to "5005" , and it's working fine to me

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
VxxxxC
  • 1
  • 1
0

firebase serve --only functions --port

-1

For me, it wasn't working when a VPN was on.

DamjanDabo
  • 97
  • 3