Reputation: 65
Upon trying to deploy index.js I get the following error in console:
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)
My code in index.js is the following:
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();
});
Upvotes: 1
Views: 2438
Reputation: 714
Just to clearify how @aofdev's comment resolved my issue, I had written the code for a function say functionA and it's triggering route was say /users/quotes{quoteId}
but then copied this function down when I wanted to create a new function say functionB. Changed the body implementation of the function and the function name without still not changing the triggering route. So now I have two functions with same triggering route and only one function( FunctionA) actually exported but then, when I deploy and wanted to trigger my function( FunctionA) for testing, I get the ReferenceError
due to functionB being executed even though it was exported.
Check to ensure that this function is exported at the level of your index.js/ts file and doesn't have the same trigger route as another function in your functions project.
Hope this helps.
Upvotes: 0
Reputation: 1812
You try to change this. if you need deploy cloud functions
// 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
Upvotes: 1