【问题标题】:why firebase functions onCall not deploy?为什么不部署firebase函数onCall?
【发布时间】:2018-12-07 15:52:05
【问题描述】:

我在 index.ts 中有打字稿代码

import * as functions from "firebase-functions";
import * as cors from "cors";

cors({ origin: true });

exports.myFunc = functions.https.onCall((data, context) => {
  const { uid } = context.auth;

  return { uid };
});

如果我尝试部署此功能:

firebase deploy --only functions:myFunc

我回来了:

函数:指定了以下过滤器,但不匹配任何 项目中的函数:myFunc

我做错了什么?

【问题讨论】:

  • 所以您将 TypeScript 代码放在以 .j​​s 结尾的文件中?这似乎不对。
  • @DougStevenson importexport 不是打字稿代码,而是 es6 语法
  • @AhmedM.Kamal 这不是问题所在。根据配置(他们没有显示),这个文件可能永远不会被编译,也可能永远不会被部署者拾取。
  • @DougStevenson 抱歉,我打错了。正确的 index.ts

标签: javascript typescript firebase google-cloud-functions


【解决方案1】:

我发现了一个错误。 Typescript 在目录lib/functions/src/index.js 中编译我的 .js 文件,但我的 package.json 文件具有指向主文件的外部路径

{
  ...
  "main": "lib/index.js",
  ...
}

我改成

{
  ...
  "main": "lib/functions/src/index.js",
  ...
}

它成功了!

【讨论】:

    【解决方案2】:
    // index.js
    
    const functions = require('firebase-functions');
    const cors = require('cors');
    
    cors({ origin: true });
    
    exports.myFunc = functions.https.onCall((data, context) => {
      const { uid } = context.auth;
      return { uid };
    });
    

    然后$ firebase deploy --only functions

    【讨论】:

      猜你喜欢
      • 2021-04-10
      • 2018-11-02
      • 2020-01-14
      • 2022-09-26
      • 2019-01-26
      • 2019-02-22
      • 2022-01-22
      • 2018-12-16
      • 1970-01-01
      相关资源
      最近更新 更多