【问题标题】:Error deploying Firebase Cloud Functions on Node runtime 10, but works on Node runtime 8在节点运行时 10 上部署 Firebase 云函数时出错,但在节点运行时 8 上有效
【发布时间】:2020-09-11 12:37:41
【问题描述】:

我正在尝试在我的云功能中实现 geofirestore。

函数在Node runtime 8中部署正确,但在runtime 10中部署出错。

我的 index.js 标头如下:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const { GeoCollectionReference, GeoFirestore, GeoQuery, GeoQuerySnapshot } = require('geofirestore');
admin.initializeApp();

const db = admin.firestore();
const geofirestore = new GeoFirestore(db);

我在 Node 运行时 10 上收到的错误消息是:

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint C:\Users\naabr\Projects\flutter\mg_sos\firebase\functions
> eslint .

+  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
!  functions: missing required API cloudbuild.googleapis.com. Enabling now...
+  functions: required API cloudfunctions.googleapis.com is enabled

!  functions: Cloud Functions will soon require the pay-as-you-go (Blaze) billing plan to deploy. To avoid service disruption, upgrade before 2020-06-23. For more information, see: https://firebase.google.com/support/faq#functions-runtime

i  functions: preparing functions directory for uploading...
i  functions: packaged functions (42.88 KB) for uploading
+  functions: functions folder uploaded successfully
i  functions: updating Node.js 10 function newUserCreated(us-central1)...
i  functions: updating Node.js 10 function emergencyNotification(us-central1)...
i  functions: updating Node.js 10 function emergencyUpdate(us-central1)...
!  functions[newUserCreated(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs

【问题讨论】:

  • 您是否按照错误消息的提示通过链接了解如何查看函数日志?你在那里发现了什么?请编辑问题以显示完整的错误。
  • 在不知道日志显示什么的情况下,我们建议的任何内容都是在黑暗中拍摄的。请检查日志(您提供的错误日志末尾的链接),并更新问题。请在您这样做时发表评论,以便我们知道您已经进行了更新。
  • 嘿,感谢您的 cmets!.. 我设法通过删除 Node 8 函数并将它们重新创建为 Node 10 函数来让它工作......(我对所有的人都很陌生这个并且无法弄清楚如何让日志记录工作,所以我只是尝试了这个,我们很好)
  • 您能否发布您的解决方案作为答案,以便其他人可以更轻松地发现解决方法?

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


【解决方案1】:

转到 functions 文件夹,然后打开 package.json 文件。现在更改文件如下所示

"engines": {
"node": "10"
}

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

然后,再次部署函数。

【讨论】:

  • 这解决了我的问题。谢谢。
  • 这个技巧不再起作用了。错误:您的项目 xcdy 必须在 Blaze (pay-as-you-go) 计划中才能完成此命令。在升级完成之前,无法启用所需的 API cloudbuild.googleapis.com。 To upgrade, visit the following URL
【解决方案2】:

在转换到 Node 运行时 10(并从不同的文件夹部署)时,我收到了相同的错误消息,但这是因为我的依赖项。

添加依赖项时我需要

npm install dependencyName

在函数文件夹中,而不是根文件夹中。

【讨论】:

  • 这是我的问题,我不小心在根目录而不是函数文件夹中运行 npm install 后,从根文件夹中删除了 package-lock.json、package.json 和 node_modules。很好的 Josh,无需降级!
  • 这也发生在我身上!我在云函数中使用 axios,但不小心将它安装在“函数”目录之外。
【解决方案3】:

在functions/package.json中更改以下内容:

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

【讨论】:

    【解决方案4】:

    我遇到了同样的错误。就我而言,我在 package.json 中缺少依赖项(在函数文件夹中,而不是项目根文件夹中)。 你可以运行

    npm install xyz
    

    从你的函数目录(你写函数的地方) 希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-08-23
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 2015-01-05
      • 1970-01-01
      • 2022-08-02
      • 1970-01-01
      • 2021-12-26
      相关资源
      最近更新 更多