简体   繁体   English

为什么Firebase函数onCall无法部署?

[英]why firebase functions onCall not deploy?

i have typescript code in index.ts 我在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 };
});

If i try deploy this function: 如果我尝试部署此功能:

firebase deploy --only functions:myFunc

I get back: 我回来了:

functions: the following filters were specified but do not match any functions in the project: myFunc 函数:指定了以下过滤器,但与项目中的任何功能都不匹配:myFunc

what am I doing wrong ? 我究竟做错了什么 ?

i found a mistake. 我发现了一个错误。 Typescript compile my .js files in directory lib/functions/src/index.js but my package.json file have outher path to main file Typescript编译目录lib/functions/src/index.js .js文件,但我的package.json文件具有主文件的路径

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

i changed to 我改为

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

and it worked! 而且有效!

// 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 };
});

then $ firebase deploy --only functions 然后$ firebase deploy --only functions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM