From 6cd07e2aac66b4762156faf70aa680948423870a Mon Sep 17 00:00:00 2001 From: Yuchen Shi Date: Fri, 16 Apr 2021 13:47:12 -0700 Subject: [PATCH] Prevent v8 database trying to register with v9 app. --- packages/database/index.node.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/database/index.node.ts b/packages/database/index.node.ts index 277365da490..5388bd2d102 100644 --- a/packages/database/index.node.ts +++ b/packages/database/index.node.ts @@ -123,8 +123,10 @@ try { // @firebase/app when used together with the js sdk. More detail: // https://github.com/firebase/firebase-js-sdk/issues/1696#issuecomment-501546596 // eslint-disable-next-line import/no-extraneous-dependencies, @typescript-eslint/no-require-imports - const firebase = require('@firebase/app').default; - registerDatabase(firebase); + const firebase = require('@firebase/app').default; // Only present for v8, undefined for v9 (should skip). + if (firebase) { + registerDatabase(firebase); + } } catch (err) { // catch and ignore 'MODULE_NOT_FOUND' error in firebase-admin context // we can safely ignore this error because RTDB in firebase-admin works without @firebase/app