Skip to content

Does Firebase Admin SDK support Firestore Emulator? #575

@ChromeQ

Description

@ChromeQ

I have a project using firestore, functions and hosting.
Until recently I was happily working locally with firebase serve --only functions,hosting and that would work with the production firestore.
Using the new firestore emulator I read loads suggesting to use emulator over serve, and my functions have firestore triggered functions which I would like to test locally.

When I firebase serve --only functions I get a Ignoring trigger "onDocumentCreate" because the Cloud Firestore emulator is not running. This suggests the trigger can work with the emulator.
When I have the firestore emulator running in another process, the functions serve does not detect the firestore emulator running.
So finally I try firebase emulators:start --only firestore,functions which starts up fine with all triggers.

As soon as Firestore code is executed I get the error:

Google API requested!
    - URL: "https://oauth2.googleapis.com/token"
    - Be careful, this may be a production service.
>  { Error: Getting metadata from plugin failed with error: Header field "authorization" must have only a single value
>      at Http2CallStream.call.on (/home/dav/dev/lms/functions/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
>      at emitOne (events.js:121:20)
>      at Http2CallStream.emit (events.js:211:7)
>      at process.nextTick (/home/dav/dev/lms/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22)
>      at _combinedTickCallback (internal/process/next_tick.js:132:7)
>      at process._tickCallback (internal/process/next_tick.js:181:9)
>    code: 'ERR_HTTP2_HEADER_SINGLE_VALUE',
>    details: 'Getting metadata from plugin failed with error: Header field "authorization" must have only a single value',
>    metadata: Metadata { options: undefined, internalRepr: Map {} } }

How can I make firebase-admin work with emulated firestore and functions?

import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';

admin.initializeApp();
const firestore = admin.firestore();

const foo = firestore.collection('colName').doc('docId')
    .onSnapshot(snap => {
        console.log(snap);
    });

Using all the latest packages:

    "firebase-admin": "^8.1.0",
    "firebase-functions": "^3.0.1",
    "firebase-tools": "^7.0.0",

OS: Linux Ubuntu 18.04
NPM version: 6.9.0
Node version: 8.15.0

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions