我尝试运行
firebase deploy --only functions
将新的 Node.js 云函数上传到 firebase,但出现了此错误:
⚠ functions: failed to update function projects/my-app/locations/us-central1/functions/fixGeoLocErr
Failed to update function projects/busfluence-app/locations/us-central1/functions/fixGeoLocErr
⚠ functions: HTTP Error: 400, Validation failed for trigger projects/my-app/locations/us-central1/triggers/sendnewoffernotification-890412: The request was invalid: generic::not_found: Project has no namespace.: invalid argument
⚠ functions: failed to create function projects/busfluence-app/locations/us-central1/functions/sendNewOfferNotification
Failed to create function projects/busfluence-app/locations/us-central1/functions/sendNewOfferNotification
Functions deploy had errors with the following functions:
sendNewOfferNotification(us-central1)
fixGeoLocErr(us-central1)
i functions: cleaning up build files...
Error: There was an error deploying functions:
- Error Failed to update function fixGeoLocErr in region us-central1
- Error Failed to create function sendNewOfferNotification in region us-central1
一个名为
fixGeoLocErr
的现有功能无法更新,而我制作的名为 sendNewOfferNotification
的新功能无法上传。
我能想象这是一个问题的唯一原因是我最近向 firebase 添加了一个新的 iOS 应用程序,并已将我的项目切换为使用新的应用程序。执行此操作后,我没有对任何云功能配置进行任何更改。这会是问题所在吗?
实际上,我最终完全重新安装了所有 Firebase CLI 工具,并且还在我的计算机上重新安装了 node/npm,但没有效果。有什么想法吗?
这是我试图部署的功能:
const {onValueCreated} = require("firebase-functions/v2/database");
const {logger} = require("firebase-functions");
exports.sendNewNotification = onValueCreated("/transactions", (event) => {
logger.log(`A new document was created`);
});
但是,
onValueCreated
功能是为实时数据库而设计的。在我的项目中,我一直在使用 Cloud Firestore,并且未设置 RTDB,因此出现 Project has no namespace
错误。
相反,我这样做了:
const {onDocumentWritten} = require("firebase-functions/v2/firebase");
const {logger} = require("firebase-functions");
exports.sendNewNotification = onDocumentWritten("/transactions", (event) => {
logger.log(`A new document was created`);
});
这使用 Cloud Firestore 的触发器而不是 RTDB。