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",
Related
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"
[Error: [firestore/unavailable] The service is currently unavailable. This is a most likely a transient condition and may be corrected by retrying with a backoff.]
I encountered this sudden error with the same code which worked fine yesterday
This error occurred when I tried to get data from firebase firestore
using these versions
"#react-native-firebase/app": "^14.7.0",
"#react-native-firebase/auth": "^14.7.0",
"#react-native-firebase/database": "^14.7.0",
"#react-native-firebase/firestore": "^14.7.0",
"#react-native-firebase/messaging": "^14.7.0",
"#react-native-firebase/storage": "^14.7.0",
"react": "18.0.0",
"react-native": "0.68.0",
The problem is with Android Emulator v 31.3.10
Turning off wifi in the emulator and turning on its data connection
works for me. Check these for further details.
Firebase doesn't work on Android Studio Emulator
I fixed permanently by following these steps.
Its issue with emulator version.
https://github.com/firebase/flutterfire/issues/9607#issuecomment-1263065653
Deploying our Firebase Function suddenly stopped working recently. Running firebase functions:log provided an insight that was not very helpful:
2022-02-15T06:53:12.421579Z E XXX:
{"#type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Build
failed: curl: (22) The requested URL returned error: 404 \n\ngzip:
stdin: unexpected end of file\ntar: Child returned status 1\ntar:
Error is not recoverable: exiting now; Error ID:
08522105"},"authenticationInfo":{"principalEmail":"XXXX"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"XXXX"}
The deployment works fine for other projects, but fails even for older versions of this project (ones that have been deployed successfully in the past).
I received a 404 error from gcloud.functions.deploy on deploy:
Deploying function (may take a while - up to 2 minutes)...
.
For Cloud Build Stackdriver Logs, visit: https://console.cloud.google.com/logs/viewer?project=x-xxx-dev&advancedFilter=resource.type%3Dbuild%0Aresource.labels.build_id%3D35aac420-xx-4cd1-b7be-blah%0AlogName%3Dprojects%2Fxxx-xxx-dev%2Flogs%2Fcloudbuild
................failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: curl: (22) The requested URL returned error: 404
The root cause error is not visible here, but if you click on the Stackdriver logs link in the console output, there will be more details. In my case, the root error was that yarn 2.4.3 couldn't be downloaded # https://github.com/yarnpkg/yarn/releases/download/v2.4.3/yarn-v2.4.3.tar.gz
I did not expect to be using yarn 2 (berry) at this point, but in my package.json I was not explicit:
"engines": {
...
"yarn": ">=1.22.0"
},
By changing to accept only version 1, the problem was resolved:
"engines": {
...
"yarn": "^1.22.0"
},
I still don't understand why npm resolved this missing version.
The firebase log was not useful at all, but since Functions are built using "Google Cloud Build" I was able to get more insight into what's wrong by opening the Logs Explorer in Google Cloud Console. Select the resource type "Cloud Build" and there you will find logs of each build step and which one failed.
In this case, it fails to fetch the yarn-version specific in our package.json (1.22). Changing it to "1.22.17" (latest as of now) fixed the build.
"engines": {
"node": "14",
"npm": "8.1",
"yarn": "1.22.17"
},
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...
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!