简体   繁体   English

错误:“路径”参数必须是字符串类型。 收到未定义。 firebase deploy --only 功能

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

I am trying to deploy my firebase cloud functions.我正在尝试部署我的 firebase 云功能。 When I run firebase deploy --only functions after adding my functions to the index.js file it gives me the error mentioned above.当我在将我的函数添加到 index.js 文件后运行firebase deploy --only functions ,它给了我上面提到的错误。

here is my firebase.json file:这是我的 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"
  }
}

here is my index.js file:这是我的 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);
});

I tried running firebase deploy --only functions with the hello world snippet they provide.我尝试使用他们提供的 hello world 代码段运行firebase deploy --only functions It worked fine with that.它工作得很好。

As the error message says, you need to always pass a path to the functions.firestore.document(...) function, to determine on which document paths the function triggers.正如错误消息所说,您需要始终将路径传递给functions.firestore.document(...)函数,以确定函数在哪些文档路径上触发。

You do this correctly here:您在此处正确执行此操作:

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

But you are not passing a path in these two cases:但是在这两种情况下,您并没有通过路径:

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

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

If you also want them to trigger on user documents, just like with onCreate , they'd be:如果您还希望它们在用户文档上触发,就像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.

相关问题 尝试使用gh-pages部署我的React应用程序,但收到此错误消息:“file”参数必须是string类型。收到的类型未定义 - Trying to deploy my React app with gh-pages but got this error message : The “file” argument must be of type string. Received type undefined 图片上传错误:TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型未定义 - Image Upload Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined ytdl:“url”参数必须是字符串类型。 接收类型未定义 - ytdl: The "url" argument must be of type string. Received type undefined Firebase 与 react: TypeError: Path must be a string。 收到未定义 - Firebase with react: TypeError: Path must be a string. Received undefined (hashlips_art_engine-1.1.2_patch_v5) “路径”参数必须是字符串类型。 收到未定义 - (hashlips_art_engine-1.1.2_patch_v5) The "path" argument must be of type string. Received undefined axios “url”参数必须是字符串类型。 收到类型未定义错误 - axios The "url" argument must be of type string. Received type undefined error ““路径”参数必须是字符串。收到未定义的“如何解决此错误 - "The "path" argument must be string. Received undefined"how do I resolve this error TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 收到未定义和代码:'ERR_INVALID_ARG_TYPE' - TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined and code: 'ERR_INVALID_ARG_TYPE' 错误:TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 尝试 node utils/nftport/uploadFiles.js 时收到 undefined - error:TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined when trying node utils/nftport/uploadFiles.js Webpack 类型错误'TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型布尔值(真)' - Webpack type error 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type boolean (true)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM