firebase-tools: Error deploying v2 Firebase function containing a dash (replaces dash with dot in entry point after deployment)
[REQUIRED] Environment info
firebase-tools: 11.22.0
Platform: macOS
[REQUIRED] Test case
firebase deploy --only functions:my-function with the below source code
[REQUIRED] Steps to reproduce
In my use case, I am trying to modify the function name at deploy time by converting from camelCase to kebab-case to conform to FCFv2 naming standards while not having a single lowercase-token function name.
My index.js is as follows:
for (let f = 0, fl = files.length; f < fl; f++) {
const file = files[f];
// camelCase makes it so we can have directory file names
// (e.g. "db/users/onwrite.f.js" -> dbUsersOnWrite)
// Strip off '.f.js'
const filePrefix = (file.split("/").pop() as string).slice(0, -5);
const functionName = kebabCase(filePrefix);
if (
!process.env.FUNCTION_NAME ||
process.env.FUNCTION_NAME === functionName
) {
const actualFunction = require(file)[filePrefix];
// NOTE: Functions must have the same name as their file name for this to work
exports[functionName] = actualFunction;
}
}
And my function code is as follows:
import { https } from "firebase-functions/v2";
export const myFunction = https.onCall(...);
When I deploy my-function, I get the following error:
i functions: creating Node.js 16 function my-function(us-central1)...
Could not create or update Cloud Run service run-analysis-engine, Container Healthcheck failed. 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?project=my-project&resource=cloud_run_revision/service_name/my-function/revision_name/my-function-00001-[redacted]
For more troubleshooting guidance, see https://cloud.google.com/run/docs/troubleshooting#container-failed-to-start
Functions deploy had errors with the following functions:
my-function(us-central1)
Additionally, here is info from the logs:
DEFAULT 2023-02-10T22:50:25.000000Z Function 'my.function' is not defined in the provided module.
DEFAULT 2023-02-10T22:50:25.000000Z Did you specify the correct target function to execute?
DEFAULT 2023-02-10T22:50:25.000000Z Could not load the function, shutting down.
WARNING 2023-02-10T22:50:25.000000Z Container called exit(1).
In the logs and the functions console, the executed function/entry point is my.function and not my-function. Why is the dash being replaced with a dot in both of these places? I have also attempted to declare my function this way:
const myFunction = https.onCall(...);
module.exports = {
'my-function': myFunction
}
with the same result.
I do also want to note that if I repeat this behavior (including leaving the function file name and function declaration in camelCase) but instead .toLowerCase() the function, everything works perfectly.
Is there any possible way to deploy a Firebase Cloud Function v2 with a hyphen in the first place? I am trying to work around the character set issue until uppercase letters are eventually allowed, but it seems my team is stuck with lowercasing our function names if we want to convert a function to v2, unless there is a way around this issue.
[REQUIRED] Expected behavior
The function deploys with its entry point as my-function, or at least does not error when its name is my-function and its entry point is my.function.
[REQUIRED] Actual behavior
The function’s entry point gets swapped to my.function and the container health fails and the function cannot deploy. I also have to delete this function before I can ever deploy another.
This is a similar issue to https://github.com/firebase/firebase-functions/issues/1131
I do not believe the debug logs contain any additional useful information.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 16 (3 by maintainers)
This should be fixed now on the latest version; uppercase characters are allowed now.
Hey, I’ve found a solution to this:
Doing this you’d get the following route:
/test-coffeeorlogin-authorlogin-recoverPassword.You simply create an object containing what you want on a specific route, rename the function that the route is going to acces to what you want and that’s it.
Happy new year, folks.
Got it, that makes sense. Having to conform to both k8s label name requirements and JS variable name requirements is a rather unfortunate overlap.
Hi all, sorry for the delay and thanks for providing a detailed description of the issue. I was also able to reproduce the error by trying to deploy functions with dashes in their function names, similar to below:
I’ll notify our engineers about this issue so that they can take a look.