[英]Firebase Cloud functions - Failed to load function definition from source: Restful Endpoints - Failed to add the endpoint defined
I am using firebase cloud functions with typescript in node 16.14.我在节点 16.14 中使用 firebase 云函数和 typescript。
My index.ts look like this:我的 index.ts 看起来像这样:
import { FunctionParser } from "firebase-backend";
exports = new FunctionParser({rootPath: __dirname, exports,
verbose:true}).exports;
Here is the addEvent.endpoint.ts:这是 addEvent.endpoint.ts:
import { Request, Response } from "express";
import { Endpoint, RequestType } from "firebase-backend";
// import * as functions from "firebase-functions";
const fs = require('firebase-admin');
const serviceAccount = require('./key.json');
fs.initializeApp({
credential: fs.credential.cert(serviceAccount)
});
const db = fs.firestore();
export default new Endpoint(
"addEvent",
RequestType.POST,
(request: Request, response: Response) => {
const message = request.body["message"];
db.collection("events").doc("adkakjagjh").set("message", message);
return response.status(201).send({
message: message
});
}
)
I have the following file structure as below.我有以下文件结构如下。
My cloud functions worked just recently but some change that I am not aware of has made them error out with the following error for just this 1 endpoint "addEvent.endpoint.ts": Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Restful Endpoints - Failed to add the endpoint defined in C:/Development/EventFeeder/Backend/Firebase/functions/lib/users/restful/addEvent.endpoint.js to the users Api.我的云功能最近才工作,但我不知道的一些更改使它们出错,仅针对此 1 个端点“addEvent.endpoint.ts”出现以下错误:错误:无法从源加载 function 定义:无法生成来自 function 来源的清单:错误:Restful 端点 - 无法将 C 中定义的端点添加:/Development/EventFeeder/Backend/Firebase/functions/lib/users/restful/addEvent.endpoint.js 到用户 Api。
How can I fix this issue?我该如何解决这个问题? I am not sure what I need to try because the error message is not that specific about the problem's root cause.
我不确定我需要尝试什么,因为错误消息并没有具体说明问题的根本原因。 I did not find any post about this particular problem.
我没有找到关于这个特定问题的任何帖子。
I try to run the functions with "npm run build && firebase emulators:start --only functions" and "firebase emulators:start"我尝试使用“npm run build && firebase emulators:start --only functions”和“firebase emulators:start”运行函数
The issue disappear when I remove the addEvent.endpoint.ts file当我删除 addEvent.endpoint.ts 文件时,问题消失了
I was facing the same problem, and I figured out that you shouldn't initialize the app (initializeApp()) in each endpoint, just write it in the index.ts one time and everything will work as expected.我遇到了同样的问题,我发现你不应该在每个端点初始化应用程序 (initializeApp()),只需将它写入 index.ts 一次,一切都会按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.