Hi I am unable to deploy functions using firebase, I am getting the below error. On trying to look at the logs could not find anything concrete.
If someone can please help me to resolve this issue.
Below are the necessary details.
error displayed :
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.
Functions deploy had errors with the following functions:
app(us-central1)
i functions: cleaning up build files...
Error: There was an error deploying functions
On running function:log got the below :
2022-09-15T08:09:56.119842Z ? app: at require (node:internal/modules/cjs/helpers:102:18)
2022-09-15T08:09:56.119851Z ? app: at Object.<anonymous> (/workspace/index.js:10:32)
2022-09-15T08:09:56.119860Z ? app: at Module._compile (node:internal/modules/cjs/loader:1105:14)
2022-09-15T08:09:56.119869Z ? app: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
2022-09-15T08:09:56.119877Z ? app: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-09-15T08:09:56.119893Z ? app: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-09-15T08:09:56.119902Z ? app: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-09-15T08:09:56.120112Z ? app: Could not load the function, shutting down.
2022-09-15T08:09:56.385832481Z E app: Function cannot be initialized. Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging
2022-09-15T08:09:56.573338Z E app: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation."},"authenticationInfo":{"principalEmail":"[email protected]"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/pixstory-biz/locations/us-central1/functions/app"}
2022-09-15T08:12:27.847972Z N app: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","authenticationInfo":{"principalEmail":"[email protected]"},"requestMetadata":{"callerIp":"122.179.194.233","callerSuppliedUserAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.6.1 Safari/605.1.15,gzip(gfe),gzip(gfe)","requestAttributes":{"time":"2022-09-15T08:12:27.950588Z","auth":{}},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.DeleteFunction","authorizationInfo":[{"resource":"projects/pixstory-biz/locations/us-central1/functions/app","permission":"cloudfunctions.functions.delete","granted":true,"authorizationLoggingOptions":{"permissionType":"ADMIN_WRITE"},"resourceAttributes":{}}],"resourceName":"projects/pixstory-biz/locations/us-central1/functions/app","request":{"name":"projects/pixstory-biz/locations/us-central1/functions/app","@type":"type.googleapis.com/google.cloud.functions.v1.DeleteFunctionRequest"},"resourceLocation":{"currentLocations":["us-central1"]}}
2022-09-15T08:12:30.436268Z N app: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{},"authenticationInfo":{"principalEmail":"[email protected]"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.DeleteFunction","resourceName":"projects/pixstory-biz/locations/us-central1/functions/app"}
2022-09-15T08:13:04.366285Z I undefined: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","authenticationInfo":{"principalEmail":"[email protected]"},"requestMetadata":{"callerIp":"122.179.194.233","callerSuppliedUserAgent":"FirebaseCLI/11.8.0,gzip(gfe),gzip(gfe)","requestAttributes":{"time":"2022-09-15T08:13:04.714274Z","auth":{}},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.GenerateUploadUrl","authorizationInfo":[{"resource":"projects/pixstory-biz/locations/us-central1","permission":"cloudfunctions.functions.sourceCodeSet","granted":true,"authorizationLoggingOptions":{"permissionType":"ADMIN_WRITE"},"resourceAttributes":{}}],"resourceName":"projects/pixstory-biz/locations/us-central1","request":{"parent":"projects/pixstory-biz/locations/us-central1","@type":"type.googleapis.com/google.cloud.functions.v1.GenerateUploadUrlRequest"},"response":{"uploadUrl":"https://storage.googleapis.com/uploads-975633983912.us-central1.cloudfunctions.appspot.com/20dd78fd-5c6a-4b23-8d2a-abce039a468e.zip?GoogleAccessId=service-284892888168@gcf-admin-robot.iam.gserviceaccount.com&Expires=1663231384&Signature=o24h25y7yLfKyAzOs8jE8%2BRiXQs9KzeIU2unV6TMBFLYSccAmvzKGB3qk0ps2nXZL0EpBQSAXqhj9nFxTLOWA8AxmS4bD0Z1vBuMpbBNps8mI%2FeY1k5wPnpDdPupG7CLIm%2FHd6H8iXhuF7CTJ7V8C6x%2FIOQP1XiEdOduwoGbUF%2BL9JAn4OpR4JCThIOkCHUu1zkb2lO6otqsfj%2BIYWNQTIJom5c4NgvlzDLFq2sRm2IFSmXhMUa1DVJy7zUEIJVCEdJn1n9MoAQdKqNSC%2BZ5XQSl0uylK5wQI1SyCi%2F32SDEzUK4QZV45dy8XTI2rIOIwdjo7w9s%2BadPzeeDVcN%2FqA%3D%3D","@type":"type.googleapis.com/google.cloud.functions.v1.GenerateUploadUrlResponse"},"resourceLocation":{"currentLocations":["us-central1"]}}
2022-09-15T08:13:04.706769Z I undefined: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{},"authenticationInfo":{"principalEmail":"[email protected]"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.GenerateUploadUrl","resourceName":"projects/pixstory-biz/locations/us-central1"}
2022-09-15T08:13:06.711244Z N app: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","authenticationInfo":{"principalEmail":"[email protected]"},"requestMetadata":{"callerIp":"122.179.194.233","callerSuppliedUserAgent":"FirebaseCLI/11.8.0,gzip(gfe),gzip(gfe)","requestAttributes":{"time":"2022-09-15T08:13:07.105263Z","auth":{}},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.CreateFunction","authorizationInfo":[{"resource":"projects/pixstory-biz/locations/us-central1/functions/app","permission":"cloudfunctions.functions.create","granted":true,"authorizationLoggingOptions":{"permissionType":"ADMIN_WRITE"},"resourceAttributes":{}}],"resourceName":"projects/pixstory-biz/locations/us-central1/functions/app","request":{"location":"projects/pixstory-biz/locations/us-central1","function":{"entryPoint":"app","name":"projects/pixstory-biz/locations/us-central1/functions/app","httpsTrigger":{"securityLevel":"SECURE_ALWAYS"},"dockerRegistry":"ARTIFACT_REGISTRY","runtime":"nodejs16","labels":{"deployment-tool":"cli-firebase"},"sourceUploadUrl":"https://storage.googleapis.com/uploads-975633983912.us-central1.cloudfunctions.appspot.com/20dd78fd-5c6a-4b23-8d2a-abce039a468e.zip?GoogleAccessId=service-284892888168@gcf-admin-robot.iam.gserviceaccount.com&Expires=1663231384&Signature=o24h25y7yLfKyAzOs8jE8%2BRiXQs9KzeIU2unV6TMBFLYSccAmvzKGB3qk0ps2nXZL0EpBQSAXqhj9nFxTLOWA8AxmS4bD0Z1vBuMpbBNps8mI%2FeY1k5wPnpDdPupG7CLIm%2FHd6H8iXhuF7CTJ7V8C6x%2FIOQP1XiEdOduwoGbUF%2BL9JAn4OpR4JCThIOkCHUu1zkb2lO6otqsfj%2BIYWNQTIJom5c4NgvlzDLFq2sRm2IFSmXhMUa1DVJy7zUEIJVCEdJn1n9MoAQdKqNSC%2BZ5XQSl0uylK5wQI1SyCi%2F32SDEzUK4QZV45dy8XTI2rIOIwdjo7w9s%2BadPzeeDVcN%2FqA%3D%3D"},"@type":"type.googleapis.com/google.cloud.functions.v1.CreateFunctionRequest"},"resourceLocation":{"currentLocations":["us-central1"]}}[![enter image description here][1]][1]
index.js
const functions = require("firebase-functions");
// const admin = require('firebase-admin');
// admin.initializeApp();
const express = require('express');
//require('./db/mongoose');
require('../db/mongoose');
//const notification = require('./db/models/notification');
var bodyParser = require('body-parser');
const app = express();
const userprofileInformation = require('../routers/userprofileinfo');
const userCampaigninformation = require('../routers/userProjectInformation');
const searchPerson = require('../routers/search');
const filter = require('../routers/filter');
const multer = require('multer');
const jwt = require('jsonwebtoken');
const http = require('http').createServer(app);
let fs = require('fs');
const loginDetails = require('../routers/login_page');
//const jwt = require('jsonwebtoken');
const UserController = require('../routers/user_controller');
require('dotenv').config();
const filterPage = require('../routers/filter');
var cors = require("cors");
var cookieParser = require('cookie-parser');
var path = require('path');
const controller = require('../controllers/razorpay_controller');
const excelToJson = require('convert-excel-to-json');
const userProfile = require('../models/search');
const issueRaiseUser = require('../routers/user_issue');
app.use(cors());
const portCheck = process.env.PORT || 3001
app.use(express.json({limit: "50mb"}));
app.use(express.urlencoded({limit: "50mb", extended: true}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, '../pix/public-flutter')));
app.get('/', (_, res) => {
res.sendFile(path.resolve(__dirname, '../pix/public-flutter/index.html'));
});
app.use(UserController);
app.use(userprofileInformation);
app.use(userCampaigninformation);
app.use(filter);
app.use(issueRaiseUser);
//app.use(searchPerson);
exports.app = functions.https.onRequest(app);
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"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": "16"
},
"main": "index.js",
"dependencies": {
"bcryptjs": "^2.4.3",
"convert-excel-to-json": "^1.7.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0",
"JSONStream": "^1.3.5",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.3.1",
"mongoose-sequence": "^5.3.1",
"multer": "^1.4.4",
"n": "^9.0.0",
"natural": "^5.2.3",
"node-nlp": "^4.24.0",
"nodemailer": "^6.7.5",
"otp-generator": "^4.0.0",
"razorpay": "^2.8.1",
"remove-stopwords": "^1.0.3",
"stable": "^0.1.8",
"stopword": "^2.0.2",
"stripe": "^9.11.0",
"twilio": "^3.78.0",
"validator": "^13.7.0"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
File structure:
[![Files][2]][2]
[2]: https://i.sstatic.net/6BGj7.png