7

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

函数在 Node 运行时 8 中正确部署,但在运行时 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);

我在节点运行时 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
4

4 回答 4

8

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

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

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

然后,再次部署功能。

于 2020-07-10T07:24:08.040 回答
4

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

添加依赖项时,我需要

npm install dependencyName

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

于 2020-07-30T05:19:58.930 回答
2

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

npm install xyz

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

于 2020-09-15T11:31:50.927 回答
1

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

"engines": {
  "node": "8"
}
于 2020-09-05T12:24:18.167 回答