【问题标题】:Can't deploy Cloud Functions for Firebase无法为 Firebase 部署 Cloud Functions
【发布时间】:2017-09-01 16:02:18
【问题描述】:

我在部署功能时很好,但后来它停止工作,我不知道为什么。我已经恢复到示例代码(from herehere):

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// Listens for new messages added to /messages/:pushId/original and creates an
// uppercase version of the message to /messages/:pushId/uppercase
exports.makeUppercase = functions.database.ref('/messages/{pushId}/original')
    .onWrite(event => {
      // Grab the current value of what was written to the Realtime Database.
      const original = event.data.val();
      console.log('Uppercasing', event.params.pushId, original);
      const uppercase = original.toUpperCase();
      // You must return a Promise when performing asynchronous tasks inside a Functions such as
      // writing to the Firebase Realtime Database.
      // Setting an "uppercase" sibling in the Realtime Database returns a Promise.
      return event.data.ref.parent.child('uppercase').set(uppercase);
    });

但是现在,当我运行 firebase deploy --only functions 时,我得到:

=== Deploying to 'mydb'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
+  runtimeconfig: all necessary APIs are enabled
+  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (2.04 KB) for uploading
!  functions: Upload Error: Cannot read property 'response' of undefined
i  starting release process (may take several minutes)...
i  functions: updating function makeUppercase...
!  functions[makeUppercase]: Deploy Error: Function load error: Node.js module defined by file index.js is expected to export function named makeUppercase
+  functions: 0 function(s) deployed successfully.


Functions deploy had errors. To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

怎么了?

控制台显示相同的错误消息,没有更多解释:

【问题讨论】:

  • 请显示部署命令的输出,将 --debug 添加到命令行参数。
  • 带有 --debug 的部署命令的输出太大了,无法放在这里...如果您认为它可能有帮助,我可以捕获它并通过电子邮件发送给您。我复习了一下,并没有学到很多东西。
  • @frank-van-puffelen 我看到你添加了一个“google-cloud-functions”标签。这不是和 Firebase 函数完全不同吗?
  • Cloud Functions for Firebase Google Cloud Functions,但添加了集成 Firebase 功能的附加功能。您可以将您的日志发送到 pastebin 之类的服务并在此处链接。
  • 见【Cloud Function 和 Firebase Functions 有什么区别? ](stackoverflow.com/questions/42854865/…)。

标签: javascript firebase google-cloud-functions firebase-tools


【解决方案1】:

Firebase 工具的 3.6.0 版刚刚发布...安装该版本后,部署工作正常!

【讨论】:

    【解决方案2】:

    通过终端进入您的项目:

    npm install
    firebase deploy
    

    【讨论】:

      【解决方案3】:

      通过查看日志来检查实际日志很有帮助

      firebase functions:log
      

      具体问题将在此处显示。我有时会遇到像丢失包一样简单的错误

      【讨论】:

        猜你喜欢
        • 2021-08-26
        • 2022-07-28
        • 1970-01-01
        • 2017-10-09
        • 1970-01-01
        • 2018-06-17
        • 2017-08-08
        • 2018-08-18
        • 2017-10-09
        相关资源
        最近更新 更多