在尝试部署 index.js 时,我在控制台中收到以下错误:
Error: Error occurred while parsing your function triggers.
ReferenceError: firebase is not defined
at Object.<anonymous> (/private/var/folders/c3/fnyhf3gzz472z6fp_80gn/T/fbfn_12024O1uxG/index.js:10:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11
at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)
我在index.js中的代码如下:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const serviceAccount = require('./DERPTYDERP-DERP123abc-firebase-adminsdk-1o2i3u4y5t.json');
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: "https://derptyderpt-123abc.firebaseio.com/"
});
firebase.database().ref().once('value',function(snapshot){
let something = snapshot.val();
});
最佳答案
你尝试改变这一点。如果您需要部署云功能
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp();
//Name Triggers testData
exports.testData = functions.database.ref('/data/{pushId}').onWrite(event =>
{
// Grab the current value of what was written to the Realtime Database.
const original = event.data.val();
});
Reference: Cloud Functions Trigger a database function
关于node.js - NodeJS Firebase 引用错误 : firebase is not defined at Object. <匿名>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46460703/