firebase-tools: firebase functions:shell - Port 5000 is not open, could not start functions emulator

[REQUIRED] Environment info

firebase-tools: 7.2.2

Platform: macOS

[REQUIRED] Test case

firebase functions:shell

[REQUIRED] Steps to reproduce

  1. $ npm install -g firebase-tools
  2. $ npm install firebase-functions@latest firebase-admin@latest --save
  3. firebase functions:shell

[REQUIRED] Expected behavior

firebase shell runs as advertised

[REQUIRED] Actual behavior

CLI Output: Port 5000 is not open, could not start functions emulator. firebase-debug.log

[debug] [2019-08-18T03:02:45.322Z] ----------------------------------------------------------------------
[debug] [2019-08-18T03:02:45.324Z] Command:       /usr/local/bin/node /usr/local/bin/firebase functions:shell
[debug] [2019-08-18T03:02:45.324Z] CLI Version:   7.2.2
[debug] [2019-08-18T03:02:45.324Z] Platform:      darwin
[debug] [2019-08-18T03:02:45.324Z] Node Version:  v10.15.3
[debug] [2019-08-18T03:02:45.330Z] Time:          Sat Aug 17 2019 23:02:45 GMT-0400 (Eastern Daylight Time)
[debug] [2019-08-18T03:02:45.330Z] ----------------------------------------------------------------------
[debug] 
[2019-08-18T03:04:19.141Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2019-08-18T03:04:19.141Z] > authorizing via signed-in user
[2019-08-18T03:04:19.142Z] [iam] checking project ddme-329f1 for permissions ["firebase.projects.get"]
[2019-08-18T03:04:19.143Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/ddme-329f1:testIamPermissions
 permissions=[firebase.projects.get]
[2019-08-18T03:04:24.132Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Sun, 18 Aug 2019 03:04:23 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, server-timing=gfet4t7; dur=111, alt-svc=quic=":443"; ma=2592000; v="46,43,39", accept-ranges=none, transfer-encoding=chunked

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 16
  • Comments: 24 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Seems to be related to the new portfinder release. https://github.com/http-party/node-portfinder/issues/84

The code used by the emulator fails with the latest version (1.0.22):

await pf.getPortPromise({ port, stopPort: port });

A workaround could be (besides using the old 1.0.21 version) :

await pf.getPortPromise({ port, stopPort: port + 1 });

QuickFix Edit the file firebase-tools/lib/emulator/controller.js in node_modules and change yield pf.getPortPromise({ port, stopPort: port }) to yield pf.getPortPromise({ port, stopPort: port + 1 })

There is an open pull request which fixes this “bug”: https://github.com/http-party/node-portfinder/pull/86

In case someone want to find global node_modules to apply the quick fix. you can run npm root -g to see where your global node_modules are.

Thanks everyone for the discussion. As we’ve noticed, this is caused by a breaking change in portfinder and now fixed by https://www.npmjs.com/package/portfinder/v/1.0.23 . If you’re interested in how and why this broke us, see https://github.com/http-party/node-portfinder/issues/89

A clean install / update like npm install -g firebase-tools@latest should fix the issue.

Combining both @micksatana and @lookfirst ideas together into the true one liner.

sed -i '' 's/stopPort: port/stopPort: port+1/' $(npm root -g)/firebase-tools/lib/emulator/controller.js

YMMV.

@Hacksore Only if you’ve installed firebase-tools globally, which is something I personally try to avoid with npm packages. I’d rather go with any alias in my .bashrc file:

export PATH="${PATH}:./node_modules/.bin"

Or just always use npm run firebase which adds node_modules/.bin to your path.

The reason I avoid this is because this allows me to have different versions of dependencies in each project. If I decide I never want to use firebase again, I just remove the projects and I don’t have to remember to remove anything globally. I also don’t have version conflicts and strange behaviour this way.

Yes, the cost is more disk space, but disk is cheap.

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.

@meltedmoon the mentioned node_modules is not the node_modules in your project folder, but rather the node_modules for the packages you install globally. I can give you an example possible location in MacOS and you’ll need to figure out the similar location in case you’re in Windows.

/⁨usr⁩/⁨local⁩/⁨lib⁩/⁨node_modules⁩/⁨firebase-tools⁩/⁨lib⁩/⁨emulator⁩/controller.js

Thanks for your kind help, I able to find it. Windows location for firebase-tools is: *C:\Users[user]\AppData\Roaming\npm\node_modules\firebase-tools*

Seems to be related to the new portfinder release. http-party/node-portfinder#84 (comment)

The code used by the emulator fails with the latest version (1.0.22):

await pf.getPortPromise({ port, stopPort: port });

A workaround could be (besides using the old 1.0.21 version) :

await pf.getPortPromise({ port, stopPort: port + 1 });

QuickFix Edit the file firebase-tools/lib/emulator/controller.js in node_modules and change yield pf.getPortPromise({ port, stopPort: port }) to yield pf.getPortPromise({ port, stopPort: port + 1 })

There is an open pull request which fixes this “bug”: http-party/node-portfinder#86

I can confirm the QuickFix is working for me.

Firebase Tools: 7.2.2 Node: 12.8.1 OS: Fedora 30 Workstation

@Jank1310 I just did your suggestion and get :

i  Starting emulators: ["functions"]
✔  functions: Using node@8 from host.
Error: An unexpected error has occurred.

have any idea?

@akildemir There is no need to apply the quick fix. You can just upgrade the global module.

npm i -g firebase-tools

Seems to be related to the new portfinder release. http-party/node-portfinder#84

The code used by the emulator fails with the latest version (1.0.22):

await pf.getPortPromise({ port, stopPort: port });

A workaround could be (besides using the old 1.0.21 version) :

await pf.getPortPromise({ port, stopPort: port + 1 });

QuickFix Edit the file firebase-tools/lib/emulator/controller.js in node_modules and change yield pf.getPortPromise({ port, stopPort: port }) to yield pf.getPortPromise({ port, stopPort: port + 1 })

There is an open pull request which fixes this “bug”: http-party/node-portfinder#86

I found that updating the global firebase-tools package to the latest version (7.2.4) fixed the issue for me

If you are facing this issue in macOS Pro then this solution is for you.

In MacOS , Port 5000 may be claimed by a new “AirPlay Receiver”. This can be disabled in Settings -> Sharing:

I’m also adding the Screenshot of settings panel for disabling AirPlay Receiver.

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

One line fix on OSX:

sed -i '' 's/stopPort: port/stopPort: port+1/' node_modules/firebase-tools/lib/emulator/controller.js