0

I'm trying to deploy a simple function do Cloud Firestore. This function will patch the data. But whenever I attempt to deploy I get an error:

Functions deploy had errors with the following functions:
    webApi

This is the code:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as firebaseHelper from 'firebase-functions-helper/dist';
import * as express from 'express';
import * as bodyParser from 'body-parser';

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();

const app = express();
const main = express();

main.use(bodyParser.json());
main.use(bodyParser.urlencoded({extended: false}));
main.use('/api/v1', app);

const sensorsCollection = 'dadosusuarios';
export const webApi = functions.https.onRequest(main);

app.patch('/Name/:sensorId', async(req, res) => {
    try{
        await firebaseHelper.firestoreHelper.updateDocument(db, sensorsCollection, req.params.sensorId, req.body);
        res.status(200).send('Update Success');
    }catch(error){
        res.status(204).send('Patch Error');
    }
})

Database image: enter image description here

This is the error log I got from debbuging the code:

{
textPayload: "ERROR"
insertId: "da-das-47d7-925a-da-29"
resource: {2}
timestamp: "2021-01-27T01:39:05.703003866Z"
severity: "INFO"
labels: {1}
logName: "projects/automacao-com-aplicativo/logs/cloudbuild"
receiveTimestamp: "2021-01-27T01:39:05.952913755Z"
}

textPayload: "ERROR: error fetching storage source: generic::unknown: retry budget exhausted (3 attempts): fetching gcs source: unpacking source from gcs: source fetch container exited with non-zero status: 1"
insertId: "a528e7ab-dsa-47d7-dsa-9bcc6b5624bb-30"
resource: {2}
timestamp: "2021-01-27T01:39:05.703023756Z"
severity: "INFO"
labels: {1}
logName: "projects/automacao-com-aplicativo/logs/cloudbuild"
receiveTimestamp: "2021-01-27T01:39:05.952913755Z"
}
Nilton Schumacher F
  • 814
  • 3
  • 13
  • 43
  • Can you try deploying with `firebase deploy --only functions:webApi --debug` and share the content of the firebase-debug.log file that will be in your project's root directory after the deployment with the --debug flag set? It will have more information about the error. – hemauricio Jan 27 '21 at 01:37
  • This is what I Got from the debug: `[warn] ⚠ functions[webApi(us-central1)]: Deployment error. [info] Build failed: Build error details not available. Please check the logs at https://console.cloud.google.com/logs/viewer?project=automacao-com-aplicativo&advancedFilter=resource.type%3Dbuild%0Aresource.labels.build_id%3Da528e7ab-9e94-47d7-925a-9bcc6b5624bb%0AlogName%3Dprojects%2Fautomacao-com-aplicativo%2Flogs%2Fcloudbuild [info] ` – Nilton Schumacher F Jan 27 '21 at 01:41
  • @hemauricio I noticed that my project is at us-west2, and it is deploying at us-cenrtal1, does that influences in something – Nilton Schumacher F Jan 27 '21 at 01:41
  • No, that's only the default Cloud Functions location; You can deploy multiple functions in different locations. https://firebase.google.com/docs/functions/locations. If you go to the link in the warning, what are the logs saying? – hemauricio Jan 27 '21 at 01:48
  • I have made an edit with the errors I got – Nilton Schumacher F Jan 27 '21 at 01:53
  • I have attempted to use JavaScript but it just doesn't gives me error message – Nilton Schumacher F Jan 27 '21 at 02:23

2 Answers2

1

I ran into a similar issue with the same error message.

Are you deploying from your computer? If so, make sure you are using Node 12 when you deploy.

To check your current Node version, you can use node --version. If you need multiple Node versions (for different projects), I would suggest using nvm. Otherwise, you can follow this answer to a similar question to downgrade.

benyap
  • 93
  • 1
  • 9
0

There are few things to take in consideration:

  • make sure that you have the latest firebase-tools you can install the latest version with npm install -g firebase-tools
  • make sure that you are using the correct account. use firebase login. your account should have at least the role Cloud Functions Deployer
  • initialize the correct project with firebase init
  • check if you have billing enabled for your project. You cannot deploy functions with spark plan
  • check if you have any linting issues like unused variables
  • deploy your functions with firebase deploy --only functions
  • sometimes a deployment may fail for no reason and you just need to try again
Methkal Khalawi
  • 2,368
  • 1
  • 8
  • 13
  • I have made all of those steps correct, I just don't get why it isn't working – Nilton Schumacher F Jan 27 '21 at 16:30
  • How are you deploying your functions? with the cli or from the console and what command are you running. what firebase tools do you have? can you try to deploy a simple function like the one that comes with the `firebase init`? it should a simple hello world function – Methkal Khalawi Jan 28 '21 at 09:37
  • I'm deploying from the console, and I'm running firebase deploy, I'm trying to deploy the simple function that comes with firebase init (hello world) – Nilton Schumacher F Jan 28 '21 at 11:11
  • then I suggest in this case that you [contact support](https://cloud.google.com/support/docs/manage-cases) or open a [public issue tracker](https://issuetracker.google.com/u/2/issues/new?component=187195&template=802601) if you don't have a support package – Methkal Khalawi Jan 29 '21 at 10:29