5

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)

Pitouli
  • 399
  • 1
  • 4
  • 14
  • If you think this is a bug with the emulator, then file an issue on GitHub. https://github.com/firebase/firebase-tools – Doug Stevenson May 05 '20 at 03:22
  • It can be a bug, but it's even more probable that I am the cause of the problem :( I reverted all the firebase dependencies updates I made today, and the problem persists. Do you know how is created the "Channel credentials"? – Pitouli May 05 '20 at 03:35
  • 1
    Hi @Pitouli this documentation [here](https://googleapis.github.io/google-cloud-dotnet/docs/Google.Cloud.Firestore/) indicates how you need to connect your emulator and how the `ChannelCredentials` is needed and configurated. Could you please take a look at it and see if it helps you? – gso_gabriel May 05 '20 at 13:34
  • Thank you @gso_gabriel! Reinstalling all the node_modules made the trick, but it will definitely be helpful if a similar issue happens! – Pitouli May 05 '20 at 15:51
  • 1
    Deleting the node_modules did not work for me. Anyone have the same issue? – ryanulit May 09 '20 at 03:20

3 Answers3

9

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

Yuiki
  • 101
  • 4
3

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.

Pitouli
  • 399
  • 1
  • 4
  • 14
-1

I had to:

  1. remove node_modules
  2. update dependencies
  3. reinstall

as follows

cd functions
rm -rf node_modules
npm install -g npm-check-updates
ncu -u
npm install
Michael Nelles
  • 5,426
  • 8
  • 41
  • 57