【问题标题】:Problem deploying function to Cloud Firestore将功能部署到 Cloud Firestore 时出现问题
【发布时间】:2021-04-30 20:17:59
【问题描述】:

我正在尝试为 Cloud Firestore 部署一个简单的功能。此功能将修补数据。但是每当我尝试部署时,都会出现错误:

Functions deploy had errors with the following functions:
    webApi

这是代码:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as firebaseHelper from 'firebase-functions-helper/dist';
import * as express from 'express';
import * as bodyParser from 'body-parser';

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();

const app = express();
const main = express();

main.use(bodyParser.json());
main.use(bodyParser.urlencoded({extended: false}));
main.use('/api/v1', app);

const sensorsCollection = 'dadosusuarios';
export const webApi = functions.https.onRequest(main);

app.patch('/Name/:sensorId', async(req, res) => {
    try{
        await firebaseHelper.firestoreHelper.updateDocument(db, sensorsCollection, req.params.sensorId, req.body);
        res.status(200).send('Update Success');
    }catch(error){
        res.status(204).send('Patch Error');
    }
})

数据库图片:

这是我调试代码得到的错误日志:

{
textPayload: "ERROR"
insertId: "da-das-47d7-925a-da-29"
resource: {2}
timestamp: "2021-01-27T01:39:05.703003866Z"
severity: "INFO"
labels: {1}
logName: "projects/automacao-com-aplicativo/logs/cloudbuild"
receiveTimestamp: "2021-01-27T01:39:05.952913755Z"
}

textPayload: "ERROR: error fetching storage source: generic::unknown: retry budget exhausted (3 attempts): fetching gcs source: unpacking source from gcs: source fetch container exited with non-zero status: 1"
insertId: "a528e7ab-dsa-47d7-dsa-9bcc6b5624bb-30"
resource: {2}
timestamp: "2021-01-27T01:39:05.703023756Z"
severity: "INFO"
labels: {1}
logName: "projects/automacao-com-aplicativo/logs/cloudbuild"
receiveTimestamp: "2021-01-27T01:39:05.952913755Z"
}

【问题讨论】:

  • 您能否尝试使用 firebase deploy --only functions:webApi --debug 进行部署,并在设置了 --debug 标志的情况下共享部署后将位于项目根目录中的 firebase-debug.log 文件的内容?它将包含有关错误的更多信息。
  • 这是我从调试中得到的:[warn] ⚠ functions[webApi(us-central1)]: Deployment error. [info] Build failed: Build error details not available. Please check the logs at https://console.cloud.google.com/logs/viewer?project=automacao-com-aplicativo&advancedFilter=resource.type%3Dbuild%0Aresource.labels.build_id%3Da528e7ab-9e94-47d7-925a-9bcc6b5624bb%0AlogName%3Dprojects%2Fautomacao-com-aplicativo%2Flogs%2Fcloudbuild [info]
  • @hemauricio 我注意到我的项目在 us-west2,它正在部署在 us-cenrtal1,这会影响到什么
  • 不,这只是默认的 Cloud Functions 位置;您可以在不同的位置部署多个功能。 firebase.google.com/docs/functions/locations。如果您转到警告中的链接,日志说明了什么?
  • 我已经对我遇到的错误进行了编辑

标签: node.js firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

我遇到了具有相同错误消息的类似问题。

您是从您的计算机进行部署吗?如果是这样,请确保在部署时使用 Node 12

要检查您当前的 Node 版本,您可以使用node --version。如果您需要多个 Node 版本(用于不同的项目),我建议使用 nvm。否则,您可以关注this answer 到类似的问题进行降级。

【讨论】:

    【解决方案2】:

    有几件事情需要考虑:

    • 确保您拥有最新的firebase-tools,您可以使用npm install -g firebase-tools 安装最新版本
    • 确保您使用的是正确的帐户。使用firebase login。您的帐户至少应具有Cloud Functions Deployer 角色
    • firebase init初始化正确的项目
    • 检查您是否为您的项目启用了计费。您无法使用 spark 计划部署函数
    • 检查您是否有任何 linting 问题,例如未使用的变量
    • 使用firebase deploy --only functions 部署您的函数
    • 有时部署可能会无缘无故失败,您只需重试即可

    【讨论】:

    • 我已经把所有这些步骤都做对了,我只是不明白为什么它不起作用
    • 你是如何部署你的功能的?使用 cli 或从控制台以及您正在运行什么命令。你有什么firebase工具?你能尝试部署一个像firebase init 一样的简单功能吗?它应该是一个简单的 hello world 函数
    • 我正在从控制台部署,我正在运行 firebase deploy,我正在尝试部署 firebase init (hello world) 附带的简单功能
    • 那么在这种情况下,我建议您 contact support 或者如果您没有支持包,请打开 public issue tracker
    猜你喜欢
    • 2021-02-24
    • 1970-01-01
    • 2020-01-22
    • 2021-10-27
    • 2022-08-19
    • 2020-11-09
    • 1970-01-01
    • 2011-08-27
    相关资源
    最近更新 更多