An error occurred while retrieving token.
FirebaseError: Messaging: We are unable to register the default service worker. SyntaxError: Unexpected token '{'. import call expects exactly one argument. (messaging/failed-service-worker-registration).
f —_app-6e5ce7543176b121599c.js:1:8509
create — _app-6e5ce7543176b121599c.js:1:8994
(anonymous function) —_app-6e5ce7543176b121599c.js:1:639312
asyncFunctionResume
(anonymous function)
promiseReactionJobWithoutPromise.
promiseReactionJob
I am getting fcm token from localhost. But the problem occurred when I try to build my next project and start or after deploying to the server.
I tried several solution from various sources.
Basically i was getting error because of new file structure.
import "firebase/compat/messaging";
import firebase from "firebase/compat/app";
this is the new version import structure.
Related
I've updated firebase CLI today from version v.11.0.1 to v.11.1.0. Nothing else changed.
When I execute in cmd prompt any firebase commands (at least the one I use)
eg.
firebase deploy
I get this warning every couple of rows during firebase function deploy:
#firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential",
"message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to
fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while
making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND\"."
}
After deploy ends successfully, in console every few seconds I get the same output of that warning. I also tried to execute firebase login --reauth authenticate once again. I did that successfully but the warning keeps popping up.
Does anyone knows what is the cause of this and how to get rid of it?
P.S.
After additional research, after few months later, I've updated firebase-admin and fire-base functions with new versions available and tried again all suggestions on the useful link here. But still, every single suggestion I tried there is not working form me:
re-authenticate
tried $env:GOOGLE_APPLICATION_CREDENTIALS (even that was found in official Google docs), for some apparent reason this is not working at all
changed and logged with different account (owner role)
and still same OAuth 2 error
NOTE: I have not tried file location since on firebase host, I do not want to put file because of security reasons and do not think this is a good practice.
Everything is linked to this line of code:
defDB = admin.initializeApp({
databaseURL: db_instanceUrl,
credential: admin.credential.applicationDefault()
}, 'targetDB');
I am trying to have an API endpoint pages/api/sendEmail that uses nodemailer to send an email, but for some reason I get the error Can't resolve 'fs' when I try to use nodemailer with let nodemailer = require('nodemailer'). I have seen multiple posts about this always saying that this is due to the fact that I am trying to execute this in the frontend, but I am doing it in the API. I have also seen posts like this one and tried the fixes by modifying next.config.js, but after all the fixes this new error appeared:
Uncaught TypeError: util__WEBPACK_IMPORTED_MODULE_3__.TextEncoder is not a constructor
What I don't understand here is why can't I use the package in the API, since it is executed on the backend. I have seen multiple tutorials like this one that do the exact same thing.
I have a Firebase Function that subscribes to a Cloud PubSub topic. App is initialized very simply like this:
import * as admin from 'firebase-admin';
admin.initializeApp();
I'm getting this error:
"Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/srv/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
at process._tickCallback (internal/process/next_tick.js:68:7)"
Here's the weird thing. It typically works. In other words, if I trigger it a second time it works. And a third time. Most often it seems to fail the first time it runs after a new firebase deploy and possibly on a "cold start."
Not sure what I'm doing wrong and why it would fail only on the first run.
SOLVED! This answer helped:
Error: Could not load the default credentials (Firebase function to firestore)
From within a Firebase Function for an API call, I was publishing to a Cloud PubSub topic like this:
pubsub.topic(topicName).publish(dataBuffer, customAttributes)
I was not awaiting the response and was immediately sending the 2XX HTTP response back to the client. The execution seemed to continue fine, but obviously it did not behave as intended.
Sometimes the API response call itself would fail (and never publish the message), but sometimes not. In other cases, the publish would succeed but the Firebase Function subscribing to the topic would fail!
In all cases, this seemed to resolve itself after running the script a second time. For this reason, I still believe it had something to do with a cold start.
But since I changed it to await like this:
await pubsub.topic(topicName).publish(dataBuffer, customAttributes)
I have not seen this problem happen again.
This two calls are failed:
const client = algoliasearch(functions.config().algolia.app_id, functions.config().algolia.admin_id);
const client = algoliasearch(process.env.app_id, process.env.admin_id);
Error: Error occurred while parsing your function triggers.
AlgoliaSearchError: Please provide an application ID. Usage:
algoliasearch(applicationID, apiKey, opts)*
But this one, which requires hard coded api keys is ok:
const client = algoliasearch('APP_ID', 'ALGOLIA_ADMIN_KEY');
How can I avoid hardcoded way of initializing algolia client?
Deploy mechanics checks if functions.config().algolia.app_id and admin_key are filled while deploying. It is good feature!!! But messages (Error occurred while parsing your function triggers.) don't allow to understand that in deploying (aka compile) time.
I'm attempting to deploy a minimal Firebase Function based on an authentication trigger. I've worked successfully before with https and database triggers but I'm getting an error while deploying an authentication trigger (docs, reference).
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
exports.onCreateUser = functions
.region('europe-west1')
.auth.user()
.onCreate((user: admin.auth.UserRecord, context: functions.EventContext) => {
console.log(`Triggered On Create User: ${user.email}, ${user.uid}.`);
});
I receive the following error:
Ignoring trigger "onCreateUser" because the service "firebaseauth.googleapis.com" is not yet supported.
I've tried changing my engine node version from 10 to 8 or changing the region to europe-west2 or us-central1 but any variations on my configuration would throw this error.
The documentation I've referenced does not mention a limited support for these triggers. Is there any page with an overview of unsupported services and their limitations?
I seem to have mixed up my intent to run serve and deploy here. As I have been told by a very responsive support team the serve script spins up the emulator and is currently limited to the following scopes:
Functions
Firestore
Realtime Database
Hosting
For the development phase, however, you can make use of the interactive shell:
$ firebase functions:shell
✔ functions: Emulator started at http://localhost:5001
i functions: Loaded functions: onCreateUser
firebase > onCreateUser({"uid":"99999","email":"test#testing.com"})
'Successfully invoked function.'
> Triggered On Create User: test#testing.com, 99999.
> Function returned undefined, expected Promise or value