Upgrade from 11.11.1 to 12.0.0 and change from sendAll to sendEach throwing errors
Hello,
I've upgraded to latest version of firebase-admin and got some deprecation method messages. One of them was sendAll which is gonna be replaced with sendEach. I checked interfaces and description provided in firebase-admin and it look same. But after switching to new sendEach method I started to get errors like
Rejected unknown error: {\"code\":\"app/invalid-credential\",\"message\":\"Failed to determine project ID: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND\"}
- Firebase SDK version: 12.0.0
- Firebase Product: messaging
- Node.js version: 20.10.0
- NPM version: 10.2.5
What has changed? Is there different approach to authorisation or something else needed to be changed? Is there any migration guide for upgrade from v11 to v12?
Thank you
Also while debugging I have noticed circular dependency at
firebase-admin have dependency "@firebase/database-compat": "^1.0.2",
and database-compat have dependency back to "firebase-admin": "11.6.0",
bump
There were no changes to the credentials handling in v12. How do you initialize the SDK? Are you able to share some code samples with us?
It's not with switch to v12, that upgrade gave us only deprecation message on fcm.messaging.sendAll.. The problem is when we switch from fcm.messaging.sendAll to fcm.messaging.sendEach
Cleaned a lot.. but its visible from it hopefully - "working way"
import fcm, { messaging as fcmTypes, FirebaseError } from 'firebase-admin';
public async sendBulk(items: any[]): Promise<any> {
const fcmApp = fcm.apps?.find((app) => app?.name === credentials.credentialsId) ?? // this we have in config
fcm.initializeApp(
{
credential: fcm.credential.cert(credentials),
},
credentials.credentialsId);
fcm
.messaging(fcmApp)
// eslint-disable-next-line deprecation/deprecation -- this is deprecated method, we need to switch to .sendEach
.sendAll(items)
.then(({ responses }) => { // do some logic })
.catch((error) => { // do some logic});
}
and when we switch to .sendEach, we start getting that mentioned error
import fcm, { messaging as fcmTypes, FirebaseError } from 'firebase-admin';
public async sendBulk(items: any[]): Promise<any> {
const fcmApp = fcm.apps?.find((app) => app?.name === credentials.credentialsId) ?? // this we have in config
fcm.initializeApp(
{
credential: fcm.credential.cert(credentials),
},
credentials.credentialsId);
fcm
.messaging(fcmApp)
.sendEach(items)
.then(({ responses }) => { // do some logic })
.catch((error) => { // do some logic});
}
Interesting... can you try adding projectId to see if that solves the issue?
initializeApp(
{
credential: fcm.credential.cert(credentials),
projectId: `xxx-xxxxxx-xxx`, // this line
},
credentials.credentialsId);
Thank you this helped.. Before it did not help because we had bad setup of tests which I fixed with this.. Thank you.. Anyway, is there any reason why sendEach is calling RPC one by one? Instead of sendAll where it sent all at once? Its 2-2.5 times slower than sendAll :( Thank you
The backend API that was used by sendAll has been deprecated so we had to re implement the functionality using the send API, which sends multiple requests to the backend. We are aware of the performance issues and looking for ways to further optimize the functionality. Stay tuned!
(@jonathanedey FIY)
When will sendAll stop working?
I think it will stop working on June 20, 2024: https://firebase.google.com/support/faq/#fcm-depr-features