You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Cloud Functions中集合名称含空格部署触发报错求助

Firestore Trigger Deployment Fails When Path Contains Spaces

Looks like you ran into a common gotcha with Firebase Functions and Firestore paths—spaces in your collection/document path are breaking the deployment process, which explains why it works perfectly when you use paths without spaces.

Why This Happens

Firebase's deployment tool parses Firestore trigger paths as structured strings, and unescaped spaces get misinterpreted as unintended separators. It doesn't recognize the space as part of the actual collection name unless you explicitly tell it to treat it that way.

Fixes to Try

1. Escape Spaces in the Path

Add a backslash \ before each space in your path to escape it. This tells the deployment tool to treat the space as part of the collection name instead of a separator. Here's your modified code:

exports.testFunction = functions.firestore
  .document('/hospitals/Sidra\ Outpatient\ Hospital/users/noKW8jeJLLUeN1MTerHbCbGDzT72')
  .onWrite((event) => {});

2. Use Template Strings (Cleaner Alternative)

If you prefer a slightly cleaner syntax, you can use ES6 template strings—just remember to still escape the spaces:

exports.testFunction = functions.firestore
  .document(`/hospitals/Sidra\ Outpatient\ Hospital/users/noKW8jeJLLUeN1MTerHbCbGDzT72`)
  .onWrite((event) => {});

3. Rename the Collection (Long-Term Fix, If Possible)

If your business logic allows, renaming the collection to remove spaces (e.g., Sidra_Outpatient_Hospital or SidraOutpatientHospital) is a solid long-term solution. It eliminates the need for escaping entirely and aligns your paths with standard naming conventions.

Verify the Fix

After making one of these changes, re-run firebase deploy --only functions—your trigger should deploy successfully now, since the path will be parsed correctly.

内容的提问来源于stack exchange,提问作者zuest

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:35:08