In index.js, I have:
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original').onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
I literally copy-pasted the code from:
Somehow, when I deploy using
firebase deploy --only functions
I get:
Error: Error occurred while parsing your function triggers. ReferenceError: functions is not defined at Object. (/home/[USERNAME HERE]/functions/index.js:1:87) at Module._pile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Module.require (module.js:587:17) at require (internal/module.js:11:18) at /usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:21:11 at Object. (/usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:75:3)
What's going on, and how do I fix it?
In index.js, I have:
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original').onCreate((snapshot, context) => {
// Grab the current value of what was written to the Realtime Database.
const original = snapshot.val();
console.log('Uppercasing', context.params.pushId, original);
const uppercase = original.toUpperCase();
// You must return a Promise when performing asynchronous tasks inside a Functions such as
// writing to the Firebase Realtime Database.
// Setting an "uppercase" sibling in the Realtime Database returns a Promise.
return snapshot.ref.parent.child('uppercase').set(uppercase);
});
I literally copy-pasted the code from: https://firebase.google./docs/functions/get-started
Somehow, when I deploy using
firebase deploy --only functions
I get:
Error: Error occurred while parsing your function triggers. ReferenceError: functions is not defined at Object. (/home/[USERNAME HERE]/functions/index.js:1:87) at Module._pile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load (module.js:556:32) at tryModuleLoad (module.js:499:12) at Function.Module._load (module.js:491:3) at Module.require (module.js:587:17) at require (internal/module.js:11:18) at /usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:21:11 at Object. (/usr/local/nvm/versions/node/v8.9.4/lib/node_modules/firebase-tools/lib/triggerParser.js:75:3)
What's going on, and how do I fix it?
Share Improve this question asked Jul 11, 2018 at 23:48 Kento NishiKento Nishi 5981 gold badge9 silver badges24 bronze badges 3-
4
Does your
index.js
containconst functions = require('firebase-functions');
? – Bob Snyder Commented Jul 11, 2018 at 23:57 - Trying that now... – Kento Nishi Commented Jul 12, 2018 at 0:00
- I'm stupid. Thanks. – Kento Nishi Commented Jul 12, 2018 at 0:02
1 Answer
Reset to default 7As the setup documentation explains, you need to import required modules and initialize the app:
// 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();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742319667a4421551.html
评论列表(0条)