41

When I run firebase deploy I get this error message:

functions: HTTP Error: 400, Change of function trigger type or event provider is not allowed
creativecreatorormaybenot
  • 62,078
  • 29
  • 174
  • 277
Thomas David Kehoe
  • 7,232
  • 7
  • 44
  • 73

3 Answers3

84

TL;DR

firebase functions:delete yourFunction // this can be done via the Firebase Console as well
firebase deploy

Explanation

Basically, Cloud Functions expects the same trigger for every function all the time, i.e. once it is created it has to stick to its original trigger because every function name is connected to a specific trigger. The trigger can therefore only be changed by deleting the function first and then creating it again with a different trigger.

This can now be done easily by using the functions:delete command:

firebase functions:delete yourFunction

The documentation features more advanced use cases as well.

Old solution

Solution of this is basically commenting or cutting out your function and then saving the Functions file and deploying. The function will get deleted in Firebase, but after that you can insert/uncomment your function and it will deploy just fine again. This error occurs when you take a function and change the type of trigger that it uses, i.e. HTTP, database or authentication.

Firstly cut it out

/* exports.yourFunction = someTrigger... */

And then, after deploying ("firebase deploy") replace your trigger

exports.yourFunction = anotherTrigger...
Community
  • 1
  • 1
creativecreatorormaybenot
  • 62,078
  • 29
  • 174
  • 277
  • 3
    Umm, wouldn't it make more sense for Firebase to have a delete button for functions in the console? – Thomas David Kehoe Oct 02 '17 at 22:03
  • 1
    From reading another StackOverflow question, Firebase Console doesn't have a 'Delete Function' button (unlike Google Cloud Functions) because 'firebase deploy' overrides anything you do in the console, i.e., you could delete a function in the console but if you don't delete the function from your project, the next time you run 'firebase deploy' the function will appear in the console. – Thomas David Kehoe Oct 02 '17 at 22:09
  • OK, I followed your instructions and everything worked as you said. But the new function doesn't execute. I see it in the console with the 'Event' as 'ref.update /userLoginEvent', which looks right. When I login I see in the database '/userLoginEvent' changes. But the function doesn't execute, and no Watson token appears. – Thomas David Kehoe Oct 02 '17 at 22:22
  • I'm getting no error messages, on 'deploy' or in the console when I login as a different user. – Thomas David Kehoe Oct 02 '17 at 22:24
  • 1
    Oh, wait, it just worked when I tried it again! Cool! Thanks! – Thomas David Kehoe Oct 02 '17 at 22:25
  • That should be definitely documented in firebase documentation. – Teoman shipahi Oct 29 '17 at 01:52
  • 1
    Firebase now added the functionality to delete your functions from the cli like this: `firebase functions:delete yourfunction`. More info [here](https://firebase.google.com/docs/functions/manage-functions#delete_functions) – Daan Oct 18 '18 at 07:21
  • I'm getting this error even if I didn't edit the function it's complaining on – Andrey Gordeev Jul 04 '19 at 13:11
  • You can also try to update the firebase with "npm install -g firebase-tools". For me that solved the problem – yital9 Sep 10 '19 at 12:46
9

For those who stumble upon this in the future, the Cloud Functions console now offers a delete button. screenshot of the right hand side's "more" options

Adrian Murray
  • 1,369
  • 1
  • 9
  • 10
2

You can also go to the Cloud Functions panel in the Google Cloud Platform console and delete your function from there. After that you can upload the function normally from firebase CLI. Not sure why they don't have a delete function option in the firebase console.