部署firebase云功能时创建功能项目失败
Posted
技术标签:
【中文标题】部署firebase云功能时创建功能项目失败【英文标题】:Failed to create function project when deploying firebase cloud function 【发布时间】:2021-10-10 01:04:54 【问题描述】:我正在尝试从本地机器部署 firebase 功能
我运行以下代码:
firebase deploy --only functions
我收到了这个错误。
✔ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (95.46 KB) for uploading
✔ functions: functions folder uploaded successfully
i functions: creating Node.js 14 function messageNotification(us-central1)...
⚠ functions: failed to create function projects/xxx/locations/us-central1/functions/messageNotification
没有任何错误信息。它只是说明该功能未能创建。有谁知道为什么?提前致谢!
编辑
我按照约翰·汉利的建议跑了
firebase deploy --debug --only functions
并收到以下错误消息
[2021-08-05T01:49:33.605Z] <<< HTTP RESPONSE 400 "vary":"X-Origin, Referer, Origin,Accept-Encoding","content-type":"application/json; charset=UTF-8","date":"Thu, 05 Aug 2021 01:49:33 GMT","server":"ESF","cache-control":"private","x-xss-protection":"0","x-frame-options":"SAMEORIGIN","x-content-type-options":"nosniff","alt-svc":"h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"","accept-ranges":"none","transfer-encoding":"chunked"
[2021-08-05T01:49:33.605Z] <<< HTTP RESPONSE BODY "error":"code":400,"message":"The request has errors","status":"INVALID_ARGUMENT","details":["@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":["field":"event_trigger","description":"Expected value channels/channelId/messageId to match regular expression [^/]+/[^/]+(/[^/]+/[^/]+)*"]]
我意识到我编写函数的方式是错误的。我正在写它
export const messageNotification = functions.firestore
.document("channels/channelId/messageId")...
但我应该写成如下所示
export const messageNotification = functions.firestore
.document("channels/channelId/messages/messageId")
【问题讨论】:
您在日志中看到什么了吗?**firebase 函数:log** 2) 尝试 firebase deploy --debug --only 函数 嘿@JohnHanley,我运行了该代码并设法解决了问题。我已经编辑了我的问题,如上所示。如果需要,您可能希望将评论移至建议的答案。我会将其标记为正确答案。谢谢! 【参考方案1】:要调试部署,请尝试两种技术:
添加命令行选项--debug"
firebase deploy --debug --only functions
检查日志中的消息:
firebase functions:log
【讨论】:
以上是关于部署firebase云功能时创建功能项目失败的主要内容,如果未能解决你的问题,请参考以下文章
使用 Github 包作为 npm 节点模块时的 Firebase 云功能部署问题
Typescript 中的 React + Firebase 云功能无法部署