【问题标题】:How to solve TypeError: functions.https.onCall is not a function?如何解决 TypeError: functions.https.onCall is not a function?
【发布时间】:2018-09-01 10:04:20
【问题描述】:

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

昨天,我了解了Callable Cloud Functions,所以我决定在我的应用程序中尝试一下,看看我是否应该更新我现有的函数。我创建了一个简单的 Cloud Function 用于测试目的:

exports.testCall = functions.https.onCall((data, context) =>{
    console.log(context.auth.uid);
    return {response:"This means success"};
});

但是当我尝试部署这个功能时,我得到了错误:

错误:解析函数触发器时出错。

TypeError:functions.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) 在要求(内部/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)

我知道 Callable Cloud Functions 已在最新的 Firebase SDK 中引入,因此我尝试使用以下方法对其进行更新:

sudo npm install -g firebase-tools

但我还不能部署我的云功能。我也尝试了部分部署,如Firebase docs 所示,但没有成功。我在文档中遗漏了什么吗?

【问题讨论】:

标签: firebase google-cloud-functions firebase-tools firebase-cli


【解决方案1】:

仅更新 Firebase CLI 并不能解决问题,因为您还必须更新项目目录中的 Cloud Functions SDK。您提到 Firebase 项目已在今年早些时候初始化,所以那是在 Callable Cloud Functions 发布之前。

请注意,当您在 Firebase 项目中初始化 Cloud Functions 时,它会创建包含 Cloud Functions SDK 的 functions 目录。所以你(可能)在functions 目录中仍然有旧的SDK,你需要更新它。为此,导航到该目录并运行命令:

sudo npm i --save firebase-functions@latest

【讨论】:

  • 仅供参考,我必须在函数目录中本地更新 firebase-functions 包
猜你喜欢
  • 2021-06-22
  • 2018-11-14
  • 2021-07-02
  • 2021-08-12
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多