45
votes

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.

13

13 Answers

112
votes

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}
13
votes

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.

11
votes

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>
6
votes

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

6
votes

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

4
votes

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.

2
votes

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.)

1
votes

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.

1
votes

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.

1
votes

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.

1
votes

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

0
votes

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

0
votes

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)