I'm currently facing an issue during the deployment of my Firebase functions and I am seeking assistance to resolve it. While the deployment itself appears to be successful, I keep encountering the following error:
Cannot read property 'firebase-admin' of undefined npm ERR! A complete log of this run can be found in:
Dependencies:
- "firebase-admin": "^11.8.0"
- "firebase-functions": "^4.3.1"
Local Environment:
- Node version: v20
Function Code:
import * as admin from "firebase-admin";
import * as functions from 'firebase-functions';
const serviceAccount = require('./mooland-999ad-e0753014493a.json');
const app: admin.app.App = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
exports.listUsers = functions.https.onRequest(async (req, res) => {
try {
const listUsersResult = await app.auth().listUsers();
const users = listUsersResult.users.map((userRecord) => ({
id: userRecord.uid,
email: userRecord.email,
name: userRecord.displayName,
// Add more user information as needed
}));
res.json(users);
} catch (error) {
console.error('Error listing users:', error);
res.status(500).send('Internal Server Error');
}
});
Error log:
i functions: preparing src/app/_cloud-functions directory for uploading... i functions: packaged D:\Development\xxx\src\app_cloud-functions (42.41 KB) for uploading
- functions: src/app/_cloud-functions folder uploaded successfully i functions: updating Node.js 14 (1st Gen) function listUsers(us-central1)... Build failed: npm ERR! Cannot read property 'firebase-admin' of undefined
npm ERR! A complete log of this run can be found in: npm ERR!
/www-data-home/.npm/_logs/2024-01-15T16_37_23_763Z-debug.log; Error ID: beaf8772Functions deploy had errors with the following functions: listUsers(us-central1) i functions: cleaning up build files...
Error: There was an error deploying functions
{ "protoPayload": { "@type": "type.googleapis.com/google.cloud.audit.AuditLog", "status": { "code": 3, "message": "Build failed: npm ERR! Cannot read property 'firebase-admin' of undefined\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!
/www-data-home/.npm/_logs/2024-01-15T16_52_09_038Z-debug.log; Error ID: beaf8772" }, "authenticationInfo": {}, "serviceName": "cloudfunctions.googleapis.com", "methodName": "google.cloud.functions.v1.CloudFunctionsService.CreateFunction", "resourceName": "projects/xyz/locations/us-central1/functions/listUsers"
}, "insertId": "-il0dwwcmlo", "resource": { "type": "cloud_function", "labels": { "project_id": "xyz", "region": "us-central1", "function_name": "listUsers" } }, "timestamp": "2024-01-15T16:52:18.282342Z", "severity": "ERROR", "logName": "projects/xyz/logs/cloudaudit.googleapis.com%2Factivity",
"operation": { "id":
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"build": "tsc",
"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": {
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0"
},
"private": true
}
Your help in resolving this matter would be greatly appreciated.