ReferenceError:在云函数中未定义firebase [英] ReferenceError: firebase is not defined in cloud functions
问题描述
我是Firebase的新手,但是当我部署函数并执行onWrite()
方法时,这是我得到的错误:
I am new to firebase but when I deploy my functions and execute onWrite()
method this is the error I get:
ReferenceError:firebase未定义 在exports.sendJobNotification.functions.database.ref.onWrite.event上 (/user_code/index.js:11:3) 在/user_code/node_modules/firebase-functions/lib/cloud-functions.js:35:20 在process._tickDomainCallback(internal/process/next_tick.js:135:7)
ReferenceError: firebase is not defined at exports.sendJobNotification.functions.database.ref.onWrite.event (/user_code/index.js:11:3) at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:35:20 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendPaymentNotification = functions.database.ref('payments/{paymentID}').onWrite(event => {
if (event.data.previous.exists()) {
return;
}
firebase.database().ref('payments').child(event.params.paymentID).once('value').then(function(snap){
var jobData = snap.val();
console.log(jobData)
});
});
推荐答案
适用于任何使用此功能的人.您应该使用"admin"而不是火力基地".
For anyone googling that. You should use "admin" instead of "firebase".
这篇关于ReferenceError:在云函数中未定义firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!