![](/img/trans.png)
[英]Google Cloud Functions Firebase Error The default Firebase app already exists
[英]Why is Google Cloud Functions throwing a "Invalid value for config firebase.databaseURL" error when I try to initialize a firebase app?
我有一個 Google Cloud Function,可以將存在信息從 Firebase 實時數據庫同步到 Firestore 數據庫(如此 處所述)。 這是鏈接示例中的相關 Cloud Functions 代碼:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// Since this code will be running in the Cloud Functions enviornment
// we call initialize Firestore without any arguments because it
// detects authentication from the environment.
const firestore = admin.firestore();
// Create a new function which is triggered on changes to /status/{uid}
// Note: This is a Realtime Database trigger, *not* Cloud Firestore.
exports.onUserStatusChanged = functions.database.ref('/status/{uid}').onUpdate(
(change, context) => {
// Get the data written to Realtime Database
const eventStatus = change.after.val();
// Then use other event data to create a reference to the
// corresponding Firestore document.
const userStatusFirestoreRef = firestore.doc(`status/${context.params.uid}`);
// It is likely that the Realtime Database change that triggered
// this event has already been overwritten by a fast change in
// online / offline status, so we'll re-read the current data
// and compare the timestamps.
return change.after.ref.once('value').then((statusSnapshot) => {
const status = statusSnapshot.val();
console.log(status, eventStatus);
// If the current timestamp for this data is newer than
// the data that triggered this event, we exit this function.
if (status.last_changed > eventStatus.last_changed) {
return null;
}
// Otherwise, we convert the last_changed field to a Date
eventStatus.last_changed = new Date(eventStatus.last_changed);
// ... and write it to Firestore.
return userStatusFirestoreRef.set(eventStatus);
});
});
我最近收到一封來自 Google 的電子郵件,通知我需要從 NodeJS 6 更新到 NodeJS 8 或 10。由於此特定功能尚未投入生產,我繼續在 Google Cloud Console 中進行配置更改。 我現在收到以下錯誤。 我嘗試切換回 NodeJS 6,從頭開始重新創建函數,檢查 Github 問題和其他在線論壇。 似乎不再為我的 Google Cloud Function 提供連接 Firebase/Firestore 所需的環境變量。 但是,我不確定為什么會這樣。
Error: Invalid value for config firebase.databaseURL: undefined
at resourceGetter (/srv/node_modules/firebase-functions/lib/providers/database.js:101:19)
at cloudFunctionNewSignature (/srv/node_modules/firebase-functions/lib/cloud-functions.js:102:13)
at /worker/worker.js:825:24
at <anonymous> at process._tickDomainCallback (internal/process/next_tick.js:229:7)
此錯誤還顯示在 Cloud Functions 的 Stackdriver 日志中:
Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail
您應該使用 Firebase CLI 重新部署。 它在環境中做了一些特殊的事情來幫助 Firebase Admin SDK 在沒有任何參數的情況下正確初始化(添加 FIREBASE_CONFIG)。 聽起來當您在控制台中更改運行時時,您也丟失了這個特殊配置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.