簡體   English   中英

錯誤:“路徑”參數必須是字符串類型。 收到未定義。 firebase deploy --only 功能

[英]Error: The “path” argument must be of type string. Received undefined. firebase deploy --only functions

我正在嘗試部署我的 firebase 雲功能。 當我在將我的函數添加到 index.js 文件后運行firebase deploy --only functions ,它給了我上面提到的錯誤。

這是我的 firebase.json 文件:

  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ],
    "source": "functions"
  },
  "database": {
    "rules": "database.rules.json"
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  }
}

這是我的 index.js 文件:

const functions = require('firebase-functions');
const algoliasearch = require('algoliasearch');
//  get api keys for the algolia from the env variable of cloud functions
const APP_ID = functions.config().algolia.app;
const ADMIN_KEY = functions.config().algolia.key;

//  algolia client
const client = algoliasearch(APP_ID, ADMIN_KEY);
const index = client.initIndex('pals');

//  ADD algolia index from firestore database when a document is created in firestore:
exports.addToIndex = functions.firestore.document('users/{userId}').onCreate(snapshot=>{
  const data = snapshot.data();
  const objectID = snapshot.id;
  //  add objectID to algolia index
  return index.addObject({...data, objectID});
});

//  UPDATE algolia index from firestore database when a document is updated in firestore
exports.updateIndex = functions.firestore.document().onUpdate(change =>{
  //  change.after gives the document after the change
  const newData = change.after.data();
  const objectID = change.id;
  //  update objectID to algolia index
  return index.saveObject({...newData, objectID});
});

//  DELETE algolia index from firestore database when a document is deleted in firestore
exports.updateIndex = functions.firestore.document().onDelete(snapshot =>{
  //  delete objectID to algolia index
  return index.deleteObject(snapshot.id);
});

我嘗試使用他們提供的 hello world 代碼段運行firebase deploy --only functions 它工作得很好。

正如錯誤消息所說,您需要始終將路徑傳遞給functions.firestore.document(...)函數,以確定函數在哪些文檔路徑上觸發。

您在此處正確執行此操作:

exports.addToIndex = functions.firestore.document('users/{userId}').onCreate(snapshot=>{
  ...

但是在這兩種情況下,您並沒有通過路徑:

exports.updateIndex = functions.firestore.document().onUpdate(change =>{
  ...

exports.updateIndex = functions.firestore.document().onDelete(snapshot =>{
  ...

如果您還希望它們在用戶文檔上觸發,就像onCreate ,它們將是:

exports.updateIndex = functions.firestore.document('users/{userId}').onUpdate(change =>{
  ...

exports.updateIndex = functions.firestore.document('users/{userId}').onDelete(snapshot =>{
  ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM