如何解决TypeError:functions.https.onCall不是一个函数? [英] How to solve TypeError: functions.https.onCall is not a function?

查看:88
本文介绍了如何解决TypeError:functions.https.onCall不是一个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个今年早些时候创建的Firebase项目.它使用Cloud Functions在实时数据库上运行一些操作.

I have a Firebase project that I've created earlier this year. It uses Cloud Functions to run some operations on the Realtime Database.

昨天,我了解了可调用云函数,因此我决定尝试在我的应用程序中查看是否应该更新现有功能.我已经创建了一个简单的Cloud Function进行测试:

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:函数.https.onCall不是函数 在对象. (/tmp/fbfn_7614ijhDwX0NY98S/index.js:114:36) 在Module._compile(module.js:649:30) 在Object.Module._extensions..js(module.js:660:10) 在Module.load(module.js:561:32) 在tryModuleLoad(module.js:501:12) 在Function.Module._load(module.js:493:3) 在Module.require(module.js:593:17) 在要求时(internal/module.js:11:18) 在/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:18:11 在对象. (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:32:3)

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)

我知道最新的Firebase SDK中引入了可调用云函数,因此我尝试使用以下方法对其进行更新:

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

但是我还不能部署我的Cloud Function.我还尝试了部分部署,如 Firebase文档所示,但这没用.我在文档中缺少什么?

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?

推荐答案

仅更新Firebase CLI无法解决该问题,因为您还必须更新Project Directory中的Cloud Functions SDK.您提到Firebase项目已于今年早些时候初始化,因此那是在Callable Cloud Functions发布之前.

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.

请参见在Firebase项目中初始化Cloud Functions时,它将创建包含Cloud Functions SDK的functions目录.因此(可能)您在functions目录中仍然有旧的SDK,您需要对其进行更新.为此,请导航到该目录并运行命令:

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

这篇关于如何解决TypeError:functions.https.onCall不是一个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆