7

I am trying to implement geofirestore in my cloud functions.

The functions deploy correctly in Node runtime 8, but there is an error in deployment in runtime 10.

My index.js header is as below:

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);

The error message I get on Node runtime 10 is:

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
Neil Brown
  • 71
  • 2
  • 3
  • Did you follow the link to learn how to view the function logs, as the error message suggests? What did you find there? Please edit the question to show the complete errors. – Doug Stevenson May 24 '20 at 22:45
  • Without knowing what the logs show whatever we suggest will be a shot in the dark. Please check the logs (link at the end of the error log you have provided), and update the question. Please leave a comment when you do so we know you have made the update. – Waelmas May 25 '20 at 13:42
  • Hey, thanks for your comments!.. I managed to get it working by deleting the Node 8 functions and re-creating them as Node 10 functions... (I'm pretty new to all of this and couldn't figure out how to get logging to work, so I just tried this and we're good) – Neil Brown May 25 '20 at 18:25
  • 2
    Could you post your solution as an answer so that other's could spot the workaround easier? – Happy-Monad Jun 01 '20 at 08:34

4 Answers4

7

Go to the functions folder, then open package.json file. Now change the file as given below

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

to

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

Then, again deploy function.

Faizan Haidar Khan
  • 1,099
  • 1
  • 15
  • 20
  • This fixed my issue. Thanks. – Mobina Khalilzade Dec 09 '20 at 18:37
  • 2
    This trick is not working anymore. Error: Your project xcdy must be on the Blaze (pay-as-you-go) plan to complete this command. Required API cloudbuild.googleapis.com can't be enabled until the upgrade is complete. [To upgrade, visit the following URL](https://console.firebase.google.com/project/aquaestore-f139a/usage/details) – Sunil Kumar Dec 19 '20 at 08:50
4

I had the same error message when converting to Node runtime 10 (and deploying from a different folder), but it was because of my dependencies.

When adding dependencies I needed to

npm install dependencyName

in the functions folder, not the root folder.

Josh McGee
  • 443
  • 6
  • 16
  • this was my issue, i deleted the package-lock.json, package.json, and node_modules from the root folder after accidentally running npm install in the root instead of functions folder. good catch Josh, no need to downgrade! – David Sep 29 '20 at 04:30
  • This happended for me also! I was using axios in cloud functions but accidently installed it outside of the 'functions' directory. – Debojyoti Jan 12 '21 at 11:33
2

I was getting same error. In my case I was missing a dependency in package.json (In the functions folder not the project root folder). You can run

npm install xyz

From your functions directory (Where you have your functions written) Hope this helps somebody.

Junaid Nazir
  • 173
  • 1
  • 11
1

Change the following in functions/package.json:

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