firebase-tools: 7.6.0
Platform: Windows WSL 1
Provide a function name that contains a '-' The emulator will error out with an error similar to:
Error: Function name "DriveActivity-getActivity" is invalid. Function names cannot contain dashes.
The function emulator does allow for '.' in the name but those _are_ invalid in function names.
Create a function with a '-' in the name.
run firebase functions:shell
According to the Functions UI in the cloud console:
Name must start with a letter followed by up to 62 letters, numbers, or hyphens, and cannot end with a hyphen
The function name errors out the functions emulator.
Error: Function name "DriveActivity-getActivity" is invalid. Function names cannot contain dashes.
@joehan or @laurenzlong do you know which is correct? Can function names contain dashes?
Unsure if this is related, but running 7.6.1 I can't emulate my functions with hyphens in the name either, but with a different error thrown.
Log:
➜ functions git:(develop) ✗ firebase functions:shell -p 5004
✔ functions: Emulator started at http://localhost:5004
i functions: Loaded functions: auth-createUser, auth-deleteUser, verifyUser
$ firebase > auth-createUser()
Thrown:
ReferenceError: auth is not defined
$ firebase > verifyUser
[Function: bound ]
@eghernqvist I think what's happening there is it's trying to do the mathematical operation auth - createUser() and failing to find auth.
This is not legal JavaScript:
function auth-createUser() {
return 1;
}
If you try to run that you will get:
Thrown:
function auth-createUser() { return 1; }
^
SyntaxError: Unexpected token -
However Google Cloud Functions does allow dashes in function names because they are not literal JavaScript functions. Can you show how you're defining your auth-createUser function?
@samtstern I've grouped my functions in the way the Firebase CLI docs recommend grouping functions.
I'm using the emulator instead to get around this, but a small tip or note in the linked docs that shell testing requires your GC Functions to be JavaScript function compatibly named would probably help prevent others from falling into this pitfall!
@eghernqvist if we can't find a way to fix this behavior we will definitely add a documentation note. Can you show how you're grouping your functions though? I thought you'd get functions named auth.createUser() not auth-createUser() but maybe my understanding is wrong.
@samtstern Re-read the docs and it does seem like getting auth.createUser() is the intended result. Might have something to do with my setup using babel for import?
Basically my setup is this:
auth.js
const createUser = functions.auth.user()
.onCreate(() => {...})
export default { createUser }
index.js the function deploy source
import auth from './auth'
export { auth }
Tried with
import auth from './auth'
export default { auth }
// results in `default-auth-api` function name
Also tried changing it to:
import authApi from './auth'
export const auth = authApi
// results in function named `auth-api`, still
I think the info line in functions:shell is misleading. It actually produces the correct namespace despite showing the names at the top. For me, it says: Loaded functions: blah-get however I can simply type the below to invoke it:
// firebase functions:shell
blah.get({})
// index.js
exports.blah = {
get: functions.https.onCall(...)
}
Hmmm yeah there's definitely some inconsistent stuff going on here. I tried with these functions:
exports.myGroup = {
first: functions.https.onRequest(async (request, response) => {
response.json({ name: "first" });
}),
second: functions.https.onRequest(async (request, response) => {
response.json({ name: "second" });
}),
}
When I run functions:shell I see:
i functions: Loaded functions: myGroup-first, myGroup-second
However if I actually want to run the functions in the shell I need to do myGroup.first() and myGroup.second().
When I deploy (no args) I see this:
✔ functions[myGroup-second(us-central1)]: Successful create operation.
Function URL (myGroup-second): https://us-central1-fir-dumpster.cloudfunctions.net/myGroup-second
✔ functions[myGroup-first(us-central1)]: Successful create operation.
Function URL (myGroup-first): https://us-central1-fir-dumpster.cloudfunctions.net/myGroup-first
So in URL form they use the - in the name. However if I want to deploy just one of the functions with --only I need to do this:
$ firebase deploy --only functions:myGroup.first
If I use the - form, the deploy command does not work.
Ok I have sent out #1972 to address the confusion.
Here's what's going on (I asked someone who has been around Cloud Functions longer than I have):
- in function names, but we don't in the Firebase CLI (explained below)exports.group = { functionA: ..., functionB: ... } we wanted to make the process intuitive and Javascript-y. So we use . notation to refer to those functions wherever possible. You do --deploy only:group.functionA, etc.. is not a valid name in a GCF function, when we deploy we replace the . with a - so that in the URL that function would be called group-functionA. functions:shell we wanted to reflect your code, so the function is defined as group.functionA. However the log message in functions:shell was showing the deployed name, which is wrong. So I hope that makes sense! I do agree it's confusing but changing this decision now would be hugely disruptive for a small benefit. So I hope that #1972 reduces confusion.