Firebase Emulator - Suppress "Loaded functions definitions from source" - firebase

I am running firebase functions on local emulator and with the latest version of firebase-tools, I get this message repeatedly (It impacts my ability to debug). Is there a way to suppress this message.
+ functions: Loaded functions definitions from source: v1.function1, v1.function2, v1.function3.
I am using the following npm package versions
"firebase-admin": "^11.0.0"
"firebase-functions": "^4.0.2"
"firebase-tools": "^11.16.0"

Related

Failed to load function definition from source

While running firebase emulators:start, I get this error 70% of the time:
!! functions: Failed to load function definition from source: FirebaseError: User code failed to load. Cannot determine backend specification
But for some reason, restarting firebase emulator seems to fix that error temporarily - which leads me to believe it's not an issue with code or dependencies but more of something related to firebase emulator itself.
Any help would be appreciated.
OS & Firebase Details:
OS: Windows 11 (22H2)
Node Version: 18
Firebase CLI Version: 11.18.0
Firebase dependencies:
"firebase": "^9.16.0",
"firebase-admin": "^10.0.1",
"firebase-functions": "^4.2.0",
"firebase-tools": "^11.18.0",

Firebase functions missing config json

I've been away from firebase for about 2 years and just got back trying to fix couple of things in my firebase-functions. There was a plenty to update with my packages, but I got to the point where I am not sure what to do next to deploy the fixed function.
Here is the error that happens after trying to deploy a function in terminal:
lukasstateczny#Lukass-MacBook-Pro admin-pukinn % firebase deploy --only functions:mpiEnrollment
=== Deploying to 'pukinn2'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> tslint --project tsconfig.json
Tried to lint /Users/lukasstateczny/Desktop/Pukinn/admin-pukinn/functions/src/index.ts but found no valid, enabled rules for this file type and file path in the resolved configuration.
Running command: npm --prefix "$RESOURCE_DIR" run build
> build
> tsc
✔ functions: Finished running predeploy script.
i functions: preparing codebase default for deployment
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
✔ functions: required API cloudbuild.googleapis.com is enabled
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Cannot find module '../config/pukinn2-1b14e9a65ea1.json'
Require stack:
- /Users/lukasstateczny/Desktop/Pukinn/admin-pukinn/functions/lib/index.js
- /Users/lukasstateczny/Desktop/Pukinn/admin-pukinn/node_modules/firebase-functions/lib/runtime/loader.js
- /Users/lukasstateczny/Desktop/Pukinn/admin-pukinn/node_modules/firebase-functions/lib/bin/firebase-functions.js
lukasstateczny#Lukass-MacBook-Pro admin-pukinn %
Now the config folder exists, but there is no file with this name. Also I'm not sure about these weird numbers after the app name, but I guess it's probably something like a cashed file. I don't know at this point how to get this file and what values should be in it.
ANSWER: After a few helpful comments I realize I was missing serviceAccount.json file that can be found in Firebase Console -> App Settings -> Service Accounts [Tab]
I thought first firebaseConfig was enough but I was wrong.
Also couple of dependencies were outdated, so I needed to upgrade that as well, but after including the .json file the deployment was smooth as ever.
Service account template in case you are not sure how it should look:
{
"type": "service_account",
"project_id": "yourProjectName",
"private_key_id": "...a89fds980asddfs890dsa...",
"private_key": "-----BEGIN PRIVATE KEY-----\n...ahjk8123hdjak91hjkdsa...\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-0000f#yourProject.iam.gserviceaccount.com",
"client_id": "...1234567...",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/000/firebase-adminsdk-0000%40yourproject.iam.gserviceaccount.com"
}
Obviously make sure not to share real values with anyone.
I would try removing your .firebase folder which may contain a very old hosting cache file and retry the deployment if you are able to build the app locally just fine.
Additionally, prior to deploying those functions, I would verify in development that they are working as you intend using your Functions Emulator. In the React client you obviously need to use the connectEmulator function for development to be able to test you functions if you haven't already.
You also may want to go inside your functions folder, remove the build folder, run npm run build and ensure your functions are building just fine.

Emulating Firebase Database Trigger Function Error: the service "firebaseio.com" is not yet supported

UPDATE: SOLVED! The firebase-tools npm package needed updating to the latest version.
I am trying to emulate/test my cloud function (specifically a database trigger) using Firebase's firebase experimental:functions:shell command in my terminal.
Here is the result, my HTTP functions emulate but I get errors for every Firebase Database trigger function:
Your requested "node" version "6" doesn't match your global version "8"
✔ functions: Emulator started at http://localhost:5001
i functions: Watching "/Users/****/Documents/Websites/***** - Other/cloud-functions/" for Cloud Functions...
⚠ Default "firebase-admin" instance created!
⚠ Ignoring trigger "CF_NAME_HIDDEN_1" because the service "firebaseio.com" is not yet supported.
⚠ Ignoring trigger "CF_NAME_HIDDEN_2" because the service "firebaseio.com" is not yet supported.
⚠ Ignoring trigger "CF_NAME_HIDDEN_3" because the service "firebaseio.com" is not yet supported.
i functions: HTTP trigger initialized at http://localhost:5001/****-****/us-central1/CF_NAME_HIDDEN_4
I do not understand why I am getting this error or what it means:
Ignoring trigger ... because the service "firebaseio.com" is not yet supported.
My package.json includes:
"firebase": "4.6.2",
"firebase-admin": "^7.4.0",
"firebase-functions": "^2.2.1",
...
"devDependencies": {
"firebase-functions-test": "^0.1.6"
},
SOLVED:
It was simply because firebase pushed a small change to their firebase-tools and the 0.1 version difference was enough to break the emulation.
Simply running npm install -g firebase-tools fixed the issue.
The package versions went from firebase-tools#6.9.2 to firebase-tools#6.10.0...

Using the local emulator - Firebase Serve - Error: Certificate object must be an object

Goal
Use the firebase emulator and deploy firebase cloud functions locally for test and debug.
Issue
When firebase serve is run, it fails with - Error: Certificate object must be an object.
What's been tried
Following Google's documentation here, the instructions include
these steps:
To set up admin credentials for emulated functions (other than Cloud
Firestore and Realtime Database):
Open the Service Accounts pane of the Google Cloud Console.
Make sure that App Engine default service account is selected, and use the options menu at right to select Create key.
When prompted, select JSON
for the key type, and click Create. Set your Google default
credentials to point to the downloaded key:
$ export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"
$ firebase functions:shell
OR
$ firebase serve --only functions
Completing these instructions and running firebase serve... fails. Here are the logs:
Silver-Sliver:functions dchaddportwine$ firebase serve --only functions
=== Serving from '/Users/dchaddportwine/Sites/people-is-cloud-functions/functions'...
i functions: Preparing to emulate functions.
Warning: You're using Node.js v8.11.1 but Google Cloud Functions only supports v6.11.5.
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠ functions: Error from emulator. Error occurred while parsing your function triggers.
Error: Certificate object must be an object.
at FirebaseAppError.FirebaseError [as constructor] (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseAppError (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:119:28)
at new Certificate (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/auth/credential.js:106:19)
at new CertCredential (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/auth/credential.js:189:64)
at Object.cert (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/firebase-namespace.js:220:58)
at Object.<anonymous> (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/index.js:21:32)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
Question
How do I fix these two errors?
I have firebase-functions installed, and have tried npm i --save firebase-functions
⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
Thinking this has to do with GOOGLE_APPLICATION_CREDENTIALS, but I'm not sure how to verify or check what's happening here.
⚠ functions: Error from emulator. Error occurred while parsing your function triggers.
Error: Certificate object must be an object.
UPDATE
Further along in the documentation, it reads:
If you're using custom functions configuration variables, run the
following command in the functions directory of your project before
running firebase serve.
firebase functions:config:get > .runtimeconfig.json
After running this command, I no longer get the certificate error. Woot! However, I am getting new failures and not many hints from the logs.
=== Serving from '/Users/dchaddportwine/Sites/people-is-cloud-functions/functions'...
i functions: Preparing to emulate functions.
i hosting[development-is]: Serving hosting files from: ./
✔ hosting[development-is]: Local server: http://localhost:5000
Warning: You're using Node.js v8.11.1 but Google Cloud Functions only supports v6.11.5.
⚠ functions: Failed to emulate app
⚠ functions: Failed to emulate helloSlack
⚠ functions: Failed to emulate helloIssy
⚠ functions: Failed to emulate interactiveIssy
i functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.
Code
Here is the firebase cloud functions for helloSlack
exports.helloSlack = functions.https.onRequest((req, res) => {
if (req) {
res.status(200).send(req.body);
} else {
console.log("req Error...");
throw res.status(500);
}
});
Answer
Further along in the documentation, it reads:
If you're using custom functions configuration variables, run the
following command in the functions directory of your project before
running firebase serve.
firebase functions:config:get > .runtimeconfig.json
This project is using custom functions configuration variables. So, after running the config command, I no longer get the certificate error. Woot!

Error: Cannot find module “mongodb” after meteor upgrade to 1.6.1.1

edit - There is something strange: mongo appears in both package.json and in .meteor/packages files (should it appear in package.json at all?? it wasn't there before the update) but in different versions. here is my package.json:
{
"name": "something",
"version": "1.1.1",
"private": true,
"scripts": {
"start": "meteor run"
},
"dependencies": {
"#babel/runtime": "^7.0.0-beta.49",
"babel-runtime": "^6.26.0",
"bootstrap": "^3.3.7",
"google-protobuf": "^3.5.0",
"grpc": "^1.12.2",
"grpc-tools": "^1.6.6",
"meteor-node-stubs": "^0.3.3",
**"mongodb": "^3.1.0-beta4",**
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-progressbar.js": "^0.2.0",
"react-router": "^3.2.1",
"react-router-dom": "^4.2.2"
}
}
and here is my .meteor/packages:
meteor-base#1.3.0 # Packages every Meteor app needs to have
mobile-experience#1.0.5 # Packages for a great mobile UX
**mongo#1.4.2 # The database Meteor supports right now**
blaze-html-templates#1.0.4 # Compile .html files into Meteor Blaze views
reactive-var#1.0.11 # Reactive variable for tracker
tracker#1.1.3 # Meteor's client-side reactive programming library
standard-minifier-css#1.4.0 # CSS minifier run for production mode
standard-minifier-js#2.3.1 # JS minifier run for production mode
es5-shim#4.7.0 # ECMAScript 5 compatibility for older browsers
ecmascript#0.10.6 # Enable ECMAScript2015+ syntax in app code
shell-server#0.3.1 # Server-side component of the `meteor shell` command
session#1.1.7
tarang:ssl
After updating to 1.6.1.1, my app won’t run, crashing with message 'Error: Cannot find module “mongodb” '.
Tried to run meteor npm install, even took away the entire node_modules folder and built it again.
Tried to run meteor npm update.
Tried to run meteor npm install mongodb.
Tried to downgrade back to version 1.6.0.1.
Still can’t find mongodb.
Important - mongodb is there, all collections are there - I can access it through the terminal with "meteor mongo".
Any help?
If it helps - The data in the db can be erased if there is no other way.
(running on ubuntu 16.04)
Thanks
In the end, the problem was not in the project but in meteor globally, so I uninstalled and re-installed meteor globally, and everything got back to normal…
Thank you all!

Resources