Steve P
Steve P

Reputation: 19377

error passing empty credentials to firestore emulator

I am trying to seed some sample data into my local firestore emulator database. I adapted the example from this github issue

My code looks like this:

const {Firestore} = require('@google-cloud/firestore');
const {credentials} = require('grpc');

const db = new Firestore({
  projectId: 'my-project-id',
  servicePath: 'localhost',
  port: 8100,
  sslCreds: credentials.createInsecure(),
  customHeaders: {
    "Authorization": "Bearer owner"
  }
});

async function load_data() {
  await db.collection("mycollection").doc("myid").set({ foo: "test" })
}
load_data();

But I receive the error

this.credentials._getCallCredentials is not a function

Tested on node 10 and 12 with same error.

Library versions:

Is there a better approach to writing to local emulated firestore? Or is there something wrong with my code?

Upvotes: 0

Views: 354

Answers (1)

murgatroid99
murgatroid99

Reputation: 20267

The problem here is that you're trying to use two different implementations of gRPC together. Internally firestore uses @grpc/grpc-js, so that is what you should be using. You should only need to change the second line to const {credentials} = require('@grpc/grpc-js'); and switch the dependency to that library.

Upvotes: 1

Related Questions