I’m trying to get started with Cloud Functions for Firebase and trying to implement a simple onCall
handler. I have copied the default code from the documentation for v2 functions and reduced it to get the simplest possible code to rule out other issues. For reference here is a minimal index.js
:
const {onCall, HttpsError} = require("firebase-functions/v2/https");
exports.helloHttp = onCall((request) => {
return {
'data': request.data.name
}
});
and the associated package.json
:
{
"type":"module",
"dependencies": {
"firebase-functions": "^5.0.0"
}
}
When I try to run the code using the “Run Test” button in Google Cloud Functions Console I get the following error:
[9:08:51 PM] - TypeError: Cannot read properties of undefined (reading 'on')
at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:392:17
at new Promise (<anonymous>)
at /workspace/node_modules/firebase-functions/lib/common/providers/https.js:391:16
at /workspace/node_modules/firebase-functions/lib/v2/trace.js:16:28
at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:113:25
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I’m using node.js runtime version 20 and unless I’m missing something obvious, it feels like a bug in the imported onCall
function.
Does anyone have an idea of how to get onCall
to work in Cloud Functions? I could switch to using standard HTTP requests, but I want to use the authentication stuff associated with the Callables and it seems like this should be easy(?).