Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Emulator Error: Channel credentials must be a ChannelCredentials object

I am using Firebase Emulators. Until 4 hours ago, everything was working fine. But now, my emulated cloud functions trigger the following error:

>  Error with Backup TypeError: Channel credentials must be a ChannelCredentials object
>      at new ChannelImplementation (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/channel.js:67:13)
>      at new Client (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/client.js:57:36)
>      at new ServiceClientImpl (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/node_modules/@grpc/grpc-js/build/src/make-client.js:49:5)
>      at GrpcClient.createStub (/Users/pitouli/Documents/GIT/my-app/functions/node_modules/google-gax/build/src/grpc.js:220:22)

I clearly identified the problem: it appears every time I'm doing a Firestore request.

For example, this is a substract of the whole function:

  return new Promise((resolve, reject) => {
    db.doc(`users/${userId}`).update({ dbUpdated: new Date() })
      .then(() => {
        resolve();
      })
      .catch(e => reject(e));
  });

If I replace it by:

  return Promise.resolve();

I do not have the error anymore. But obviously I do not have the expected behavior anymore...

I made a big refactor (I installed eslint with airbnb style, so I had to modify quite a lot of files), so I probably made something wrong. But after few hours of research, I haven't found what would justify this error :(

I give you below a relevant extract of my code. My real code is by far longer, but I tested this extract alone: it reproduces the error (and if I replace the "markUserUpdated" functions as shown previously, then it disappears.)

Last but not least, I confirm that the Firestore emulator is working fine: the app is running well with datas from the emulator.

Thanks for your help!

index.js :

const functions = require('firebase-functions');
const { db } = require('./admin');

const DEBUG = true;

function markUserUpdated(userId) {
  return new Promise((resolve, reject) => {
    db.doc(`users/${userId}`).update({ dbUpdated: new Date() })
      .then(() => {
        if (DEBUG) console.log('User successfully marked Updated', userId);
        resolve();
      })
      .catch(e => reject(e));
  });
}

exports.writeContact = functions.firestore
  .document('users/{userId}/contacts/{contactId}')
  .onWrite((doc, context) => {
    const { userId } = context.params;
    return markUserUpdated(userId);
  });

admin.js :

const functions = require('firebase-functions');
const admin = require('firebase-admin');

const serviceAccount = require('../serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://my-app.firebaseio.com',
  storageBucket: 'my-app.appspot.com',
});

const db = admin.firestore();
const { FieldValue } = admin.firestore;
const { Timestamp } = admin.firestore;

const storage = admin.storage();

module.exports = {
  db, storage, FieldValue, Timestamp, functions,
};

Edit: the code is proceeded by Babel (I do not know if it could have an influence)

like image 355
Pitouli Avatar asked Dec 18 '22 13:12

Pitouli


2 Answers

The issue is due to the specific version of the google-gax package.

I was able to fix the problem by the following step.

$ npm i -D google-gax

like image 185
Yuiki Avatar answered Dec 20 '22 01:12

Yuiki


Deleting the functions/node_modules folder and reinstalling them all has solved the issue.

I'll come back to edit this post if I reproduce the action that made the app broke.

like image 35
Pitouli Avatar answered Dec 20 '22 03:12

Pitouli