Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mhs2342 opened this issue Aug 18, 2019 · 24 comments

Comments

@mhs2342
Copy link

mhs2342 commented Aug 18, 2019

[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.
@Chathula
Copy link

i am also having this problem. did you find a solution?

OS: Ubutnu 18.04

@Jank1310
Copy link

Jank1310 commented Aug 18, 2019

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

@alosarjos
Copy link

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

@Chathula
Copy link

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

This works fine! Thank you!

@meltedmoon
Copy link

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.

@alosarjos
Copy link

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.

It's in your global node_modules dir, not in the project one.

@can450
Copy link

can450 commented Aug 18, 2019

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

@meltedmoon
Copy link

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*

@micksatana
Copy link

micksatana commented Aug 19, 2019

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.

@lookfirst
Copy link

One line fix on OSX:

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

@Hacksore
Copy link

Hacksore commented Aug 19, 2019

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.

@lookfirst
Copy link

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

@yuchenshi
Copy link
Member

yuchenshi commented Aug 19, 2019

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 http-party/node-portfinder#89

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

bkendall pushed a commit that referenced this issue Aug 19, 2019
* Pin portfinder@1.0.21. Fix #1606.

* portfinder 1.0.23 should come with the fix.

* Update package-lock.json.
@yuchenshi
Copy link
Member

yuchenshi commented Aug 20, 2019

We've also updated the dependency in v7.2.4 so if you install npm install -g "firebase-tools@>=7.2.4" then it's guaranteed to be fixed, bypassing npm local cache, etc.

@lookfirst
Copy link

If you're interested in how and why this broke us, see http-party/node-portfinder#89

@yuchenshi

I wasted a couple hours trying to figure out what the problem was.

How about pinning ALL (instead of the current 'some') of the versions in package.json so that future versions don't screw things up?

Additionally, you should consider handling the error more gracefully (ie: a better error message and stack trace).

@Suraj-Ram
Copy link

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

@eriktrom
Copy link

bug is fixed via a revert to portfinder (yesterday) - yarn upgrade portfinder -L or npm equiv, fyi

@akildemir
Copy link

@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?

@micksatana
Copy link

micksatana commented Sep 11, 2019

@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

@TomKaltz
Copy link

I just had this issue pop up after Mac OS upgrade
MacOS: 10.15.2
firebase-tools: 7.12.1

Any ideas?

@yuchenshi
Copy link
Member

@TomKaltz Would you mind opening a new issue? That helps us a lot when triaging.

@TomKaltz
Copy link

#1935

@frazras
Copy link

frazras commented Dec 1, 2020

I found and killed the process with the help of this https://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac

lsof -i tcp:5001

Then I killed the PID with kill -9 PID

@Rehan-05
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests