0

I'm getting the error "There was an error deploying functions" when trying to deploy a newly created function. There is no other error info in the output:

i  functions: updating Node.js 22 (2nd Gen) function helloWorld(us-central1)...

Functions deploy had errors with the following functions:
        helloWorld(us-central1)

Error: There was an error deploying functions

firebase functions:log gives me nothing. The debug log has a not-very-helpful local stack trace at the end:

[2025-04-18T19:12:27.812Z] Functions deploy failed.
[2025-04-18T19:12:27.812Z] {}
[2025-04-18T19:12:27.849Z] Error: Precondition failed
    at Fabricator.updateV2Function (/home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:382:19)
    at Fabricator.updateEndpoint (/home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:155:24)
    at /home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:110:71
    at handle (/home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:89:23)
    at Fabricator.applyChangeset (/home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:110:26)
    at /home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:69:40
    at Array.map (<anonymous>)
    at Fabricator.applyPlan (/home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/fabricator.js:68:54)
    at release (/home/aldel/.nvm/versions/node/v20.15.1/lib/node_modules/firebase-tools/lib/deploy/functions/release/index.js:76:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Error: There was an error deploying functions

This is the first function in a new project, and it is literally just the helloWorld function that firebase init sets up (commented out; I just uncommented it):

import {onRequest} from "firebase-functions/v2/https";
import * as logger from "firebase-functions/logger";

export const helloWorld = onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

The function works fine in the emulator.

How can I figure out what's wrong?

1 Answer 1

1

Short solution: I had to manually delete the function with firebase functions:delete helloWorld, then deploy it for the first time manually from an interactive shell, not a CI environment. This seems worth trying if you get into a situation where you get the error shown in the question with no other information.

Possible explanation (I haven't tried to reproduce the problem to confirm this is how it happened):

I think this started with a previous failed attempt to deploy the function. The first time I tried to deploy, it was in a GitHub Action, so it could not be interactive, and it failed with this error:

i  functions: creating Node.js 22 (2nd Gen) function helloWorld(us-central1)...
Could not build the function. 

Functions deploy had errors with the following functions:
    helloWorld(us-central1)
⚠  functions: No cleanup policy detected for repositories in us-central1. This may result in a small monthly bill as container images accumulate over time.

Error: Functions successfully deployed but could not set up cleanup policy in location us-central1. Pass the --force option to automatically set up a cleanup policy or run 'firebase functions:artifacts:setpolicy' to manually set up a cleanup policy.
Error: Process completed with exit code 1.

Apparently now you have to set up that policy before you can deploy. If you do the first deploy manually from the command line, it will ask you how long to keep images before they're deleted. But it can't do that in a non-interactive CI environment. So it fails. (You probably could also make it succeed by adding the --force flag to the command in the CI environment, or by setting the policy before deploying, as suggested by the error message.)

After this, the function existed in the Firebase console, but it didn't work, and further attempts to deploy it (manually or from a CI environment) failed as described in the question.

The solution was to manually delete the function. Then when I tried to deploy manually, it asked me to set the cleanup policy, and succeeded.

2
  • The information about running non-interactively really should be in the title and the question itself (e.g. the steps to reproduce the issue) so it becomes more easily understood and searchable by others in the future who have the same issue. When I was reading the question, I was imagining you doing everything interactively on the command line. Commented Apr 18 at 21:03
  • @DougStevenson I was doing everything interactively... except, unfortunately, the first attempt, which turned out to be what caused the problem, I think. The point is it got into a state where every deploy failed until I deleted the function and started over. I don't know for sure how that happened, or if it's the only way that can happen. I'm revising the answer to be a little more clear about that.
    – aldel
    Commented Apr 20 at 0:20

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.