I have a Firebase project that I've created earlier this year. It uses Cloud Functions to run some operations on the Realtime Database.
Yesterday, I learned about the Callable Cloud Functions, so I decided to try it in my app to see if I should update my existing Functions or not. I've created a simple Cloud Function for testing purposes:
exports.testCall = functions.https.onCall((data, context) =>{
console.log(context.auth.uid);
return {response:"This means success"};
});
But when I try to deploy this function, I get the error:
Error: Error occurred while parsing your function triggers.
TypeError: functions.https.onCall is not a function at Object. (/tmp/fbfn_7614ijhDwX0NY98S/index.js:114:36) at Module._compile (module.js:649:30) at Object.Module._extensions..js (module.js:660:10) at Module.load (module.js:561:32) at tryModuleLoad (module.js:501:12) at Function.Module._load (module.js:493:3) at Module.require (module.js:593:17) at require (internal/module.js:11:18) at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11 at Object. (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)
I'm aware that Callable Cloud Functions has been introduced in the latest Firebase SDK, so I've tried updating it using:
sudo npm install -g firebase-tools
But I can't yet deploy my Cloud Function. I've also tried a partial deploy, as shown in the Firebase docs, but it didn't work. Is there something I'm missing in the documentation?
Simply updating your Firebase CLI won't solve the problem because you must also update the Cloud Functions SDK in the Project Directory. You mentioned the Firebase Project has been initialized earlier this year, so that's before the release of Callable Cloud Functions.
See, when you init Cloud Functions in your Firebase Project, it creates the functions
directory which contains the Cloud Functions SDK. So you (probably) still have the old SDK in the functions
directory and you need to update it. To do that, navigate to that directory and run the command:
sudo npm i --save firebase-functions@latest
来源:https://stackoverflow.com/questions/49437618/how-to-solve-typeerror-functions-https-oncall-is-not-a-function