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
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
}
How do I fix the deployment error related to the unhandled error cleaning up the build image?
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.
I have tried cleaning the the image file in the artifact registry in the cloud console but the error is still showing when I deploy.