Victor de Almeida
Victor de Almeida

Reputation: 1050

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.

Upvotes: 85

Views: 45828

Answers (24)

ErikWittern
ErikWittern

Reputation: 1203

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

Upvotes: 64

Adilson Cruz
Adilson Cruz

Reputation: 1

firebase serve --only functions --port

Upvotes: 0

Jay Stance
Jay Stance

Reputation: 11

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.

Upvotes: 0

VxxxxC
VxxxxC

Reputation: 11

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

Upvotes: 1

Sanjeev Gupta
Sanjeev Gupta

Reputation: 1

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

Upvotes: 0

Chidi-Nwaneto
Chidi-Nwaneto

Reputation: 654

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]

Upvotes: 1

jDev
jDev

Reputation: 21

A quick fix

npm i -g [email protected]

Upvotes: 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)

Upvotes: 2

Itay Tur
Itay Tur

Reputation: 1737

Running this command did the trick for me:

firebase emulators:start --only firestore

also close this window: cmd window to close

Upvotes: 4

Geetanshu Gulati
Geetanshu Gulati

Reputation: 782

just run command

firebase serve --only functions --host 0.0.0.0

Upvotes: 4

warfield
warfield

Reputation: 754

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.

Upvotes: 17

alok kumar
alok kumar

Reputation: 327

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

Upvotes: 15

DamjanDabo
DamjanDabo

Reputation: 172

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

Upvotes: -1

Ela
Ela

Reputation: 449

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

firebase serve -p 5001

Upvotes: 44

Venkat Kotra
Venkat Kotra

Reputation: 10753

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

Upvotes: 16

pa.duongdam
pa.duongdam

Reputation: 46

Try this way:

firebase serve --only functions -p 5002

Upvotes: 3

Tiberiu Oprea
Tiberiu Oprea

Reputation: 153

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

Upvotes: 2

A K M ALI HASAN
A K M ALI HASAN

Reputation: 1

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

Upvotes: 0

preetk
preetk

Reputation: 189

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.

Upvotes: 0

medo
medo

Reputation: 66

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

Upvotes: 0

Nestor Solalinde
Nestor Solalinde

Reputation: 593

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.

Upvotes: 22

publicmat
publicmat

Reputation: 851

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

Upvotes: 68

biggest_boy
biggest_boy

Reputation: 481

This worked for me.

Just restart your system.

Upvotes: 4

Wendigo
Wendigo

Reputation: 484

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!

Upvotes: 4

Related Questions