node.jsfirebasegoogle-cloud-functions

how to upgrade cloud function v1 to v2?


I want to try upgrading my v1 cloud function to v2.

originally, this is my function

import * as functions from "firebase-functions";
const express = require("express");
const app = express();
app.post(...);

exports.functionName = functions.region("asia-southeast2").https.onRequest(app);

Now I'm upgrading it to v2. and since v2 function name cannot contain any uppercase, i change it into ["function-name"]

import * as functions from "firebase-functions/v2";
const express = require("express");
const app = express();
app.post(...);

exports["function-name"] = functions.https.onRequest({region: "asia-southeast2"}, app);

when deploying, im receiving this error. I dont know what that's mean at all, it's very confusing.

i functions: creating Node.js 16 (2nd Gen) function on-function:function-name(asia-southeast2)... Could not create or update Cloud Run service function-name, Container Healthcheck failed. Revision 'function-name-00001-taz' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.

Logs URL: https://console.cloud.google.com/logs/viewer?xxxxxxxx For more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start

And opening the logs explorer from the said link, I get this message

Function 'function.name' is not defined in the provided module.
Did you specify the correct target function to execute?
Could not load the function, shutting down.

How could i upgrade my current v1 cloud function to v2?


Solution

  • I reproduced the exact issue following the documentation. First I successfully deployed the 1st gen cloud function. Later, while trying to deploy the 2nd gen function with a function name as function-name, I faced the same issue. But I was able to successfully deploy a function with the name functionname or function_name. This could be due to bug in firebase functions using a hyphen character (-). So I suggest you use names with either lowercase or an underscore.

    Example:

    exports.function_name = functions.https.onRequest({region: "asia-southeast2"}, app);
    

    Or

    exports.functionname = functions.https.onRequest({region: "asia-southeast2"}, app);
    

    Also feel free to raise a bug in public issue tracker.