firebase serve: supervisorPort (5001) is already in use - firebase

I built this React App, that allows users to add todo item, and mark an item as completed/active. Todo items are stored in cloud firestore.
I want to enable full-text search on the app, and one way is to create a cloud function that writes index to Algolia whenever cloud firestore witnesses a create operation.
Inside my app root directory, I initialize cloud functions and then implement the onTodoAdded function. After done, I run firebase serve under functions directory and get the errors:
=== Serving from '/Users/evan/source/react-redux-todos'...
i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.6.0 but Google Cloud Functions only supports v6.11.5.
i hosting: Serving hosting files from: build
✔ hosting: Local server: http://localhost:5000
error: SUPERVISOR error Error: listen EADDRINUSE 127.0.0.1:5001
at Server.setupListenHandle [as _listen2] (net.js:1335:14)
at listenInCluster (net.js:1383:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1509:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:61:10)
error: supervisorPort (5001) is already in use
i functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.
For a complete debug log, find here.
However, this command works fine: firebase serve --only functions.
=== Serving from '/Users/evan/source/react-redux-todos'...
i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.6.0 but Google Cloud Functions only supports v6.11.5.
i functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.
Since it says supervisorPort(5001) is already in use, I lsof -i:5001 and finds no process. I also shut down my laptop and restart, gets the same error.
I find the similar issue here, however didn't find the solution.

I still don't know the reason, but adding --port=9000 solves the problem. For example, firebase serve --only functions --port=9000. Credits to restPort (5001) is already in use #142.

I was having this same error after updating to macOS Mojave 10.14.1 (was fine with 10.14). error: supervisorPort (5001) is already in use and it led me down this rabbit hole of additional updates and configuration that eventually got it to work.
1 Update Node Packages
I updated these items to these versions (latest as of this writing)
firebase-functions: 2.1.0
firebase: 5.5.8
I deleted by node_modules folder and reinstalled all the packages.
2 Firestore Emulator Setup Required
Next time I attempted to serve, firebase gave me this error:
Setup required, please run: firebase setup:emulators:firestore
Because of the weird permissions issues I initially had with mac, I actually have to run
node_modules/.bin/firebase setup:emulators:firestore
3 Then.... Fix Java Runtime Issues
On my next serve attempt, I was presented with firestore: No Java runtime present, requesting install. Mac presents a popup leading to a page where you can "download java for mac". This isn't what you actually need. You really need the Java SE Development Kit which enables command line interface.
Then... You may get these errors the next time you try to serve.
error: restPort (5002) is already in use
error: SUPERVISOR error Error: listen EADDRINUSE 127.0.0.1:5001
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1351:14)
at listenInCluster (net.js:1392:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1501:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)
error: supervisorPort (5001) is already in use
But Firebase still ended up continuing to successfully serve somehow, despite these errors. And it still shows my app over http://localhost:5000.
Hope this helps!

Related

"invalid source token" while deploying a function to fireabse

i got wired issued with firebase deployment using:
firebase deploy -P dev
the error is
✔ functions[testFunction(us-central1)] Successful update operation.
Invalid source token
looks like its happen to new functions that created
when i tried to deploy specific function using:
firebase -deploy -P dev --only functions:name
its working
when i run and deploy all functions and all my apps i am getting the above error with no information
also the logs from google cloud function is:
status: {
code: 9
message: "Invalid source token"
}
firebase tools version 11.0.0
node: 14.19.3
I would suggest upgrading to atleast node 16 as there's an open issue regarding the "Invalid Source Token" on your current firebase-tools version. There's already a pull request regarding that issue and it will be fixed on the upcoming updates. Here's the github issue for reference.

How do firebase deploy?

i have problem with firebase deploy, execute the command in VS Code, showing me the next message,
I tried install, unistall dependency and no is the solution.
Thanks
Terminal:
jonatan#Jona:~/KOA/s2i-backoffice-web$ firebase deploy
=== Deploying to 'proyecto-s2i'...
i deploying functions, hosting
⚠ functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions#latest in your functions directory.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i hosting[proyecto-s2i]: beginning deploy...
i hosting[proyecto-s2i]: found 263 files in public
✔ hosting[proyecto-s2i]: file upload complete
Error: An unexpected error has occurred.
File firebase-debug.log, this is the message
[debug] [2021-07-01T15:17:30.726Z] TypeError: Canno t read property 'length' of undefined
at Object.functionMatchesAnyGroup (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/functionsDeployHelper.js:11:23)
at have.filter (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/deploymentPlanner.js:25:56)
at Array.filter (<anonymous>)
at calculateRegionalFunctionChanges (/usr /local/lib/node_modules/firebase-tools/lib/deploy/functions/deploymentPlanner.js:25:17)
at Object.createDeploymentPlan (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/deploymentPlanner.js:53:50)
at release (/usr/local/lib/node_modules/firebase-tools/lib/deploy/functions/release.js:24:48)
at process._tickCallback (internal/process/next_tick.js:68:7)
[error]
[error] Error: An unexpected error has occurred.
I had the same error with a fresh install.
I saw that firebase init had created a file at functions/index.js
However, the sole defined function inside that is commented out.
Uncommenting, and exporting a function resolved this issue.
Looks like you are uploading a bunch of files, do you need functions?
If you chose 'functions' during init, but did not define any, try this.
I just run into the exact issue. As hinted by #Sumit, After adding explicit use in code to functions, the issue solved.
exports.scheduledFunction = functions.pubsub.schedule('every 5 hours').onRun((context) => {
console.log('This will be run every 5 hours!');
});

Firebase database emulator fails to start with a java.lang.VerifyError

I have attempted the following
$ firebase emulators:start
i emulators: Starting emulators: functions, database, hosting
⚠ functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: firestore, pubsub
⚠ Your requested "node" version "nodejs10" doesn't match your global version "12"
⚠ database: Did not find a Realtime Database rules file specified in a firebase.json config file. The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i database: Database Emulator logging to database-debug.log
⚠ database: Fatal error occurred:
Database Emulator has exited with code: 1,
stopping all running emulators
i hub: Stopping emulator hub
i functions: Stopping Functions Emulator
i database: Stopping Database Emulator
⚠ database: Error stopping Database Emulator```
Looking at the database-debug.log I see:
Exception in thread "main" java.lang.VerifyError: Uninitialized object exists on backward branch 209
Exception Details:
Location:
scala/collection/immutable/HashMap$HashTrieMap.split()Lscala/collection/immutable/Seq; #249: goto
Reason:
Error exists in the bytecode
Bytecode:
[snipped]
I'm using Mac OSX. Any suggestions?
It seems I was using an incompatible java version on mac OSX. Using the java runtime from java.com solved the issue.

Firebase Functions Error while deploying to emulator

I'm trying to start new Firebase Functions project using latest versions of packages.
I've followed this tutorial https://youtu.be/DYfP-UIKxH0:
Firebase login
Firebase init
Created functions project the same way as tutorial says
Uncommented index.ts content
After that I get this error:
Starting #google-cloud/functions-emulator
[2018-04-04T19:05:12.124Z] Parsing function triggers
[2018-04-04T19:05:12.404Z] Error while deploying to emulator: TypeError: Cannot read property 'call' of undefined
TypeError: Cannot read property 'call' of undefined
at Promise (/usr/local/lib/node_modules/firebase-tools/node_modules/#google-cloud/functions-emulator/src/client/rest-client.js:34:42)
at getService.then (/usr/local/lib/node_modules/firebase-tools/node_modules/#google-cloud/functions-emulator/src/client/rest-client.js:33:16)
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
⚠ functions: Failed to emulate helloWorld
I have latest functions emulator *1.0.0-beta4.
All other libs are in latest versions...
I'm at point where I have no idea how to debug this better and how to resolve this
This error occurs if an existing process listens on port 5000. Double check if there's a process running, e.g. on Mac OS Sierra
sudo lsof -n -iTCP:5000 | grep LISTEN
Stop this process or run firebase on another port, e.g.
firebase -p 7777 serve --only functions
No need to reinstall packages. Error message is not helpful and we spent some time to find the root cause.
It turned out that it was due other app that was listening on port 5001!
Firebase serve stops with some weird message.
Just check as answer below if ports aren't busy

ionic cordova fcm notifications error with firebase

i want to implement the notifications feature by firebase on my ionic application
so after proceeding with the following command
ionic cordova plugin add cordova-plugin-fcm
and adding the google-services.json to the main folder of my ionic project I am facing the following error with no success to solve it
(node:15256) UnhandledPromiseRejectionWarning: Unhandled promise rejection
(rejection id: 1): TypeError: Invalid data, chunk must be a string or
buffer, not object
(node:15256) [DEP0018] DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero exit code.
i found on google that firebase has several bugs on it's latest version which is 4.8.2 and 4.8.1 so as well i did a downgrade to firebase 4.8.0.
as well i tried the npm install and npm cache verify and i checked that i have the same package name in my project and firebase with no success to solve it.

Resources