46

While I run the command firebase deploy I get this error:

i deploying functions

i functions: ensuring necessary APIs are enabled...

i runtimeconfig: ensuring necessary APIs are enabled...

✔ runtimeconfig: all necessary APIs are enabled

✔ functions: all necessary APIs are enabled

i functions: preparing functions directory for uploading...

i functions: packaged functions (4.04 KB) for uploading

✔ functions: functions folder uploaded successfully

i starting release process (may take several minutes)...

i functions: creating function followerNotification...

⚠ functions: failed to create function followerNotification

⚠ functions: HTTP Error: 400, The request has errors

⚠ functions: 1 function(s) failed to be deployed.

Functions deploy had errors. To continue deploying other features (such as >database), run: firebase deploy --except functions

Error: Functions did not deploy properly.

Having trouble? Try firebase deploy --help

Everything else works without problems. Only when I trying to make something with Firebase Firestore.

14 Answers 14

112

This was happening to me too, then I realized that at the 2nd level, firestore only allows documents and not collections.

I was attempting to listen to this path:

/collection/document/{wildcard}

You can either do something like

/collection/{wildcard}

or

/collection/document/collection/{wildcard}
Sign up to request clarification or add additional context in comments.

2 Comments

Okej, this cant be the answer since it does not matter how many levels you go. You can nest this as much as you want. Look at my answer
This message is still as cryptic in July 2021, including via the web editor for cloud functions. A combination of this answer and removing an errant slash from the path as suggested in adamduren's answer was the solution for me.
13

I had this problem as well. In my case it was because my trigger path had a trailing slash in the document path.

So changing:

functions.firestore
  .document('some_path/{pushId}/')

To:

functions.firestore
  .document('some_path/{pushId}')

Fixed it it for me. It seems like this is caused by a variety of issues and the firebase cli does not do a good job at explaining the reasons why.

Comments

13

For me none of the answers helped me. In the end I got a list of steps (from Google) to pinpoint the problem. If you run:

firebase --debug --only functions deploy

it will give a more detailed error-message, what was in my case:

HTTP RESPONSE BODY <?xml version='1.0' encoding='UTF-8'?><Error><Code>EntityTooLarge</Code><Message>Your proposed upload is larger than the maximum object size specified in your Policy Document.</Message><Details>Content-length exceeds upper bound on range</Details></Error>

2 Comments

it helped. I did not know maximum length of functions name is 63
This is the most versatile answer that can work for anyone encountering this error message, thanks!
7

Okej this is what you need to look at.

since you have

exports.yourFunctionName = functions.firestore.document

the thing you need to look at is the .document

Your path MUST point to a document and not to a collection.

so this will not work :

/level1/{level1Id}/level2 <- it points to a collection

this will work :

/level1/{level1Id}/level2/{level2Id}

cloud function will look for when a document has an action

Hope this will help anybody

Comments

6

The problem is that you only reference a collection and not a document like:

exports.myFunctionName = functions.firestore
      .document('users').onWrite((event) => {
        // ... Your code here
      });

You need to reference the document like:

exports.myFunctionName = functions.firestore
  .document('users/marie').onWrite((event) => {
    // ... Your code here
  });

You can also use a wildcard like:

exports.myFunctionName = functions.firestore
  .document('users/{userId}').onWrite((event) => {
    // ... Your code here
  });

It's described in here: https://firebase.google.com/docs/functions/firestore-events

Hope I could help

1 Comment

the first two functions are the same!
4

The issue was probably caused by the length of the function name.

So, if the name is:

myFunctionsFromWorksWithCustumersTiggersTests

change for a shorter name, like:

WorkWithCustumers

I hope I helped.

1 Comment

Thanks! From some playing around, it looks like function names have a max length of 64 characters.
2

I had the same error when trying to publish a function listening to a Cloud pub/sub, that began with numerical characters.

exports.nightly_pruning = functions.pubsub.topic('24hr-tick').onPublish((event) => { 
    ... 
});

Fixed it by simply changing the name:

exports.nightly_pruning = functions.pubsub.topic('nightly-tick').onPublish((event) => { 
    ... 
});

(Thanks to Nikolai Hegelstad above. I don't have the reputation to comment.)

2 Comments

I feel like this is a bit more noise, then an actual answer. You've basically just implemented Nikolai's solution. You should either edit their answer to include an example, or consider gaining enough reputation for a comment/upvote.
It's a genuine answer. I've considered gaining more reputation - and answering questions like this is the way to do so. I am just trying to add value where I can, and due to my current reputation (because I haven't spent a lot of time giving back to stack overflow, this was the only way I could).
1

I was also getting the same error until i changed my function name from

create_template_

to

create_new_template

It might be that '_'(underscore) at the end of function name resulted in this error.

Comments

1

I experienced this because of the underscore at the start of the exports function name. You can test it yourself by trying this:

exports._someLongNameWithUnderscore= functions.auth.user().onCreate(user => {
  return true;
});

exports.someLongNameWithoutUnderscore= functions.auth.user().onCreate(user => {
  return true;
});

exports.shortName= functions.auth.user().onCreate(user => {
  return true;
});

The one with the underscore at the start or end will fail with HTTP:400 and the others will deploy.

Comments

1

This can also happen if you're using the wrong Node version. I just experienced that after setting my node version to 8.x while working on functions. Switched back to v10.x and the issue disappeared.

Comments

1

If anybody is still experiencing this, in my case solution was running npm install -g firebase-tools to update cli, and adding

"engines": {
  "node": "8"
}

to package.json

Comments

0

My issue with the same error message was that Cloud Functions' pubsub doesn't seem to support topics with names beginning with numeral characters.

Comments

0

Just wanted to point out as well that the linter will reject line breaks on listener declaration, ie:

exporst.myFunc = functions.firestore
.document('collection/{uid}')
.onEvent(...)

which the linter doesnt help much and is not covered in documentation (as usual)

Comments

0

Check your database region. The function should be deployed in the same region of the database. This worked for me

1 Comment

Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.