简体   繁体   English

Firebase 云功能 - 无法从源加载 function 定义:Restful 端点 - 无法添加定义的端点

[英]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.

相关问题 我无法部署 firebase 云功能:无法从源加载 function 定义,D:\ 中没有定义“导出”主要内容 - I cannot deploy firebase cloud functions: Failed to load function definition from source, No "exports" main defined in D:\ firebase 云错误无法从源加载 function 定义 - firebase cloud error Failed to load function definition from source Firebase Function 无法从源加载 function 定义错误解决方案 - Firebase Function Failed to load function definition from source error Solution 无法从源加载函数定义:无法从函数源生成清单:SyntaxError:意外的标记“。” - Failed to load function definition from source: Failed to generate manifest from function source: SyntaxError: Unexpected token '.' Firebase 函数部署失败 - Firebase functions failed to deploy 使用云构建部署云功能失败:错误:未能获得 firebase 项目 - deploy cloud functions using cloud build failed: Error: failed to get firebase project 部署 firebase 云函数时创建函数项目失败 - Failed to create function project when deploying firebase cloud function 使用 Cloud Functions 将 Json Webhook 写入 Cloud Firestore。 云 Function 部署失败。 Function 加载用户代码失败 - Write Json Webhook to Cloud Firestore with Cloud Functions. Cloud Function Failed to Deploy. Function failed on loading user code 云 Function 构建失败 - Cloud Function Build Failed Firebase 函数部署问题(无法创建/更新函数) - Firebase functions deploy problem (Failed to create/update function)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM