【问题标题】:Can i use Cloud Firestore triggers in Cloud Functions with node 8?我可以在节点 8 的 Cloud Functions 中使用 Cloud Firestore 触发器吗?
【发布时间】:2021-02-11 06:05:25
【问题描述】:

我想解决这个阻碍我发展的问题。

当我将节点 12 的一些云功能部署到我的 Firebase 项目时,firebase-cli 输出以下内容:

HTTP 错误:400,找不到项目“PROJECT_ID”的结算帐户。必须启用计费才能激活服务“cloudbuild.googleapis.com,containerregistry.googleapis.com”才能继续。

所以我像任何开发人员一样询问谷歌并找到了这个问题Stack Overflow question

我把functions目录下的package.json改成:

"engines": {
    "node": "8"
}

成功了!但要知道我正在测试云 Firestore 触发器以使用通配符收听文档。 代码如下:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

// Getting instance of firestore
const db = admin.firestore();

//Test function
exports.writeToFirestore = functions.firestore
    .document('users/{userId}')
    .onWrite((change, context) => {
        const uid = context.params.userId;
        const newDoc = change.after.data();

        // Reference to userCards inside lawyer doc
        const userCardsDoc = db.doc(`lawyers/lawyer/userCards/userCards`);

        const newCard = {
            uid: uid,
            displayName: newDoc.displayName,
            whatsApp: newDoc.whatsApp,
            picturePath: newDoc.picturePath
        };

        userCardsDoc.set({
            cardsArray: [newCard]
        });
    });

当我更改任何用户文档的数据时,它会触发该功能,但日志显示如下: logs image

有人知道这种类型的函数触发器是否根本不适用于节点 8,我应该启用此项目中的计费帐户以使用节点 10 或最新版本进行部署,否则问题出在我的代码中。

我试过不带通配符使用这个功能还是不行!

【问题讨论】:

  • 结算帐户错误似乎与代码使用的节点版本无关。在 package.json 文件中将节点级别更改为 10 怎么样?
  • 嘿,丹!我的问题中的“日志图像”链接显示了函数执行的日志,并且出现错误:“Node.js v10.0.0 是最低要求......”。我认为该功能无法正常工作,因为此错误。
  • 你尝试过节点 10 吗?
  • 是的。但是不启用计费无法部署功能,它显示与节点12相同的错误
  • 感谢@DougStevenson answer,您应该使用 Nodejs 10 及更高版本,然后启用您的结算帐户,因为 Cloud Functions for Firebase 将依赖一些额外的付费 Google 服务:Cloud Build、Container Registry 和 Cloud贮存。请注意,Nodejs 8 可能无法正常工作,因为它已被弃用。

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


【解决方案1】:

要回答这个问题,您会收到错误消息:Node.js v10.0.0 is a minimum requirement,因为您使用的是Node.js v8Node.js v8 已于 2019 年 12 月 31 日弃用,minimum requirement 现在是 Node.js v10

现在,如果您现在使用的是 Node.js 版本 v10 及更高版本,如果您的结算帐户被禁用或未启用,则无法部署它,why you should enable your billing account?

由于计划于 2020 年 8 月 17 日更新其底层架构,Cloud Functions for Firebase 将依赖一些额外的付费 Google 服务:Cloud BuildContainer RegistryCloud Storage。这些架构更新将适用于部署到 Node.js 10 运行时的功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-27
    • 2019-01-16
    • 2018-10-16
    • 2020-02-04
    • 1970-01-01
    • 2018-03-23
    • 2019-04-12
    • 2021-03-29
    相关资源
    最近更新 更多