Firebase部署报错:服务账号格式问题求助
部署Firebase Cloud Functions时遭遇服务账号格式相关错误
报错信息
[info] Functions deploy had errors with the following functions: addmessage(us-central1) [debug] [2025-03-27T22:03:14.260Z] Not printing URL for HTTPS function. Typically this means it didn't match a filter or we failed deployment [debug] [2025-03-27T22:03:14.260Z] Checked if tokens are valid: true, expires at: 1743114349603 [debug] [2025-03-27T22:03:14.260Z] Checked if tokens are valid: true, expires at: 1743114349603 [debug] [2025-03-27T22:03:14.261Z] >>> [apiv2][query] GET https://artifactregistry.googleapis.com/v1/projects/startup36-227ae/locations/us-central1/repositories/gcf-artifacts [none] [debug] [2025-03-27T22:03:15.047Z] <<< [apiv2][status] GET https://artifactregistry.googleapis.com/v1/projects/startup36-227ae/locations/us-central1/repositories/gcf-artifacts 200 [debug] [2025-03-27T22:03:15.047Z] <<< [apiv2][body] GET https://artifactregistry.googleapis.com/v1/projects/startup36-227ae/locations/us-central1/repositories/gcf-artifacts {"name":"projects/startup36-227ae/locations/us-central1/repositories/gcf-artifacts","format":"DOCKER","createTime":"2025-03-27T20:39:45.042913Z","updateTime":"2025-03-27T20:40:24.873562Z","mode":"STANDARD_REPOSITORY","cleanupPolicies":{"firebase-functions-cleanup":{"id":"firebase-functions-cleanup","action":"DELETE","condition":{"tagState":"ANY","olderThan":"86400s"}}},"cleanupPolicyDryRun":true,"vulnerabilityScanningConfig":{"enablementConfig":"INHERITED","lastEnableTime":"2025-03-27T20:39:34.500068118Z","enablementState":"SCANNING_DISABLED","enablementStateReason":"API containerscanning.googleapis.com is not enabled."},"satisfiesPzi":true,"registryUri":"us-central1-docker.pkg.dev/startup36-227ae/gcf-artifacts","dockerConfig":{}} [debug] [2025-03-27T22:03:15.049Z] Functions deploy failed. [debug] [2025-03-27T22:03:15.049Z] {} [debug] [2025-03-27T22:03:15.061Z] TypeError: Cannot read properties of null (reading 'length') at Object.formatServiceAccount (C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\gcp\proto.js:95:24) at C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\gcp\cloudfunctionsv2.js:196:122 at Object.convertIfPresent (C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\gcp\proto.js:45:25) at Object.functionFromEndpoint (C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\gcp\cloudfunctionsv2.js:196:11) at Fabricator.createV2Function (C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:233:35) at Fabricator.createEndpoint (C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:137:24) at C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:103:64 at handle (C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:89:23) at Fabricator.applyChangeset (C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:103:26) at C:\Users\zhuan\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\release\fabricator.js:69:40 [error]
我的函数代码(index.js)
const {onRequest} = require("firebase-functions/v2/https"); const logger = require("firebase-functions/logger"); // The Firebase Admin SDK to access Firestore. const {initializeApp} = require("firebase-admin/app"); const {getFirestore} = require("firebase-admin/firestore"); initializeApp(); exports.addmessage = onRequest(async (req, res) => { // Grab the text parameter. const original = req.query.text; // Push the new message into Firestore using the Firebase Admin SDK. const writeResult = await getFirestore() .collection("messages") .add({original: original}); // Send back a message that we've successfully written the message res.json({result: `Message with ID: ${writeResult.id} added.`}); });
已尝试的解决方案(均无效)
- 降级Firebase CLI
- 从Gen2函数降级到Gen1
- 添加服务账号元数据
问题
请问该如何解决此错误?如果需要配置服务账号信息,应该在何处进行配置?我在Google Cloud Platform上已经有默认服务账号。
内容的提问来源于stack exchange,提问作者Marco
相关产品推荐
相关产品推荐

