85

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.

4
  • 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 [email protected] Commented Aug 17, 2019 at 16:05
  • using [email protected] 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 :( Commented Aug 17, 2019 at 17:44
  • 1
    @Thr3e This happened to me, too. So, I installed the grpc module in functions folder and it worked again Commented Aug 18, 2019 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. Commented Aug 4, 2021 at 13:18

24 Answers 24

68

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
Sign up to request clarification or add additional context in comments.

4 Comments

lsof -t -i tcp:5000 | xargs kill - one line alternative that pipes the output of lsof to kill (h/t @manav)
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
@warfield lsof -t -i tcp:5000 | xargs kill didn't help :(
Port 5000 is used by Airplay in newer macOS releases. You can't use it for anything else, you'll have to change the port you're using.
64

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.


Update 2024: In MacOS Sonoma, the setting for disabling the AirPlay Receiver moved to Settings -> General -> AirDrop & Handoff:

Updated screenshot of settings panel for disabling AirPlay Receiver

Comments

44

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

firebase serve -p 5001

Comments

22

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.

Comments

17
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.

Comments

16

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
    }
}

Comments

15

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

1 Comment

This solved it for me, thanks!
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!

2 Comments

thank you it fixed my issue, i just want to say that npm root -g will tell you where to look
One line fix on OSX: sed -i '' 's/stopPort: port/stopPort: port+1/' node_modules/firebase-tools/lib/emulator/controller.js
4

This worked for me.

Just restart your system.

1 Comment

Actually just restarting the code editor also worked fine, thanks though!
4

just run command

firebase serve --only functions --host 0.0.0.0

Comments

4

Running this command did the trick for me:

firebase emulators:start --only firestore

also close this window: cmd window to close

1 Comment

In my case I just had to close the terminal window and then rerun firebase emulators:start. and it worked.
3

Try this way:

firebase serve --only functions -p 5002

Comments

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"
    }
  }
}

Comments

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)

2 Comments

Facing the problem in version 7.2.2 of firebase-tools, but working in version 7.0.2 as suggested (thanks) as well as latest version 7.2.4.
In any firebase-tools version, only works with firebase-functions 3.0.2.
2

A quick fix

npm i -g [email protected]

Comments

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 [email protected]

Comments

1
{
  "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

Comments

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

Comments

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.

Comments

0

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

1 Comment

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.
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"
    }

1 Comment

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.
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.

Comments

0

firebase serve --only functions --port

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.