Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Error deploying the Firebase Cloud function.

I am unable to deploy my Firebase cloud function. The function works perfectly when I run the cloud function locally using the Firebase emulator. However, when I attempt to deploy it, I receive the following error:

 

firebase deploy --only functions

 

I get an error at the end 

 

Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually

 

Code Files

  1. firebase.js
     

 

const admin = require("firebase-admin");
const Firestore = require("@google-cloud/firestore");
const serviceAccount = require("./serviceAccountKey.json");

process.env.FIREBASE_AUTH_EMULATOR_HOST = "127.0.0.1:9099";
admin.initializeApp({
  projectId: "kadereapp-f3797",
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://KadereApp-default-rtdb.firebaseio.com",
  // databaseURL: "http://127.0.0.1:9000/?ns=kadereapp-f3797",
});

const db = new Firestore();
const rdb = admin.database();
// db.settings({
//     host: "localhost:8080",
//     ssl: false
// });

// rdb.useEmulator('localhost', 9000);
module.exports = {admin, db, rdb};

 

  • route.js:
     

 

const express = require("express");
const {
  isVehicleStaged, isVehicleOnRoute, determineDestination, getNearestRoad,
  setCustomUserClaims,
} = require("./utils");
const {db, rdb} = require("./firebase");
// const {error} = require("firebase-functions/logger");

const router = express.Router();
let ticketNo = 0;

router.get("/", (req, res) => {
  return res.status(200).send(" Welcome to Kadere App");
});

 

  • index.js:
     

 

const {onRequest} = require("firebase-functions/v2/https");
const express = require("express");
const cors = require("cors");
const routes = require("./routes");

const app = express();
app.use(cors({origin: true}));
app.use(express.json());
app.use("/", routes);

const PORT = 3000;
app.listen(PORT, () => {
  console.log("Server running http://localhost:${PORT}");
});

exports.app = onRequest(app);

 

  • package.json:
     

 

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "18"
  },
  "main": "index.js",
  "dependencies": {
    "@turf/turf": "^7.0.0",
    "axios": "^1.7.2",
    "cors": "^2.8.5",
    "express": "^4.19.2",
    "firebase-admin": "^12.1.0",
    "firebase-functions": "^5.0.0",
    "openrouteservice-js": "^0.4.0"
  },
  "devDependencies": {
    "eslint": "^8.15.0",
    "eslint-config-google": "^0.14.0",
    "firebase-functions-test": "^3.1.0"
  },
  "private": true
}

 

 
When I run the hostname for the local host using postman the cloud function responds with a '200' but when I run hostname from the firebase platform I get a '403' error.
Question
How do I fix the deployment error related to the unhandled error cleaning up the build image?
1 3 2,877
3 REPLIES 3

Hi @lupine37,

Welcome to Google Cloud Community!

The error message that you encountered indicates that there’s an issue related to cleaning build images after deploying a Firebase Cloud Function. When you deploy your function's source code to Cloud Functions, that source is stored in a Cloud Storage bucket. Cloud Build then automatically builds your code into a container image and pushes that image to the image registry. Cloud Functions accesses this image when it needs to run the container to execute your function.

To fix this deployment error related to the unhandled error cleaning up the build image, here’s some troubleshooting steps on how you can fix it:

  1. Sometimes, a temporary glitch can cause this error. Try redeploying the function again.
    firebase deploy --only functions
  2. Manually delete the cached images under the gcf_artifacts registry and retry the deployment.
  3. Add --debug flag to your Firebase deploy command to provide more detailed output that can help identify the root cause of the deployment issue.
    firebase deploy --only functions --debug
  4. Check your Cloud Function logs via Google Cloud console or Cloud Logging UI. This will also identify the errors within your function code, helping you quickly diagnose and fix issues.

I hope the above information is helpful.

Is it safe to post the url for my google console?

I have initialized a new firebase project in my react application, following the tutorials. I have then deployed my first function which would simply create a user in my firestore database.

And right off the bat I am facing this issue every time I deploy updates to my function, consuming a minute very single time I deploy.

I am wondering whether this is intended, as the error is present in a pretty blank project from the start. I find it a super annoying developer experience to be facing potential bills and being forced to crawl on these forums with issues from the start. 

Top Solution Authors