Scheduled Firestore backups
1 min read

Scheduled Firestore backups

Deploying scheduled Firestore backups in a project that already uses Functions.

I followed the official guide to create a scheduled Function on Firebase to backup Firestore on a Google Cloud bucket.

The code includes

const firestore = require('@google-cloud/firestore')
const client = new firestore.v1.FirestoreAdminClient()

but then, on pre-deploy, I got the error

Module '@google-cloud/firestore' is not listed as dependency in package.json.

And adding "@google-cloud/firestore": "^0.x.y" to package.json did not seem to be the right thing to do, because that package is already included in the Firebase sdk.

So I adapted the code from the team at Firebase to:

import * as admin from 'firebase-admin'
const client = new admin.firestore.v1.FirestoreAdminClient({})

and removed"@google-cloud/firestore": "^0.x.y" from package.json. This worked.

Subscribe to a curated newsletter

Receive an email every week with curated content about Dart and Flutter.

See previous issues of the newsletter.