首页 > 解决方案 > firebase 功能 INVALID_ARGUMENT HTTP 错误 400 在部署

问题描述

尝试在“firebase deploy”上使用 firebase 实时数据库功能解决问题 5 小时:

直到今天才吃过这个

功能是:

exports.makeUppercase = functions.database.ref('/userfollowers/{pushId}/followers')
    .onWrite((change, context) => {
      // Only edit data when it is first created.
      if (change.before.exists()) {
        return null;
      }
      // Exit when the data is deleted.
      if (!change.after.exists()) {
        return null;
      }
      // Grab the current value of what was written to the Realtime Database.
      const original = change.after.val();
      console.log('Uppercasing', context.params.pushId, original);
      const uppercase = original.toUpperCase();
      // You must return a Promise when performing asynchronous tasks inside a Functions such as
      // writing to the Firebase Realtime Database.
      // Setting an "uppercase" sibling in the Realtime Database returns a Promise.
      return change.after.ref.parent.child('uppercase').set(uppercase);
    });
which is straight out of documentation.

终端显示:

⚠  functions: failed to create function makeUppercase
HTTP Error: 400, The request has errors

云功能日志显示:

{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"INVALID_ARGUMENT"},"authenticationInfo":{"principalEmail" :"nicoaratalpes@gmail.com"},"requestMetadata":{"callerIp":"86.120.235.246","callerSuppliedUserAgent":"FirebaseCLI/3.19.0,gzip(gfe),gzip(gfe)","re​​questAttributes" :{"time":"2019-05-14T08:34:18.563Z","auth":{}},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName" :"google.cloud.functions.v1.CloudFunctionsService.CreateFunction","authorizationInfo":[{"resource":"projects/parkour-9136c/locations/us-central1/functions/makeUppercase","permission":"cloudfunctions.functions.create","granted":true,"resourceAttributes":{}},{"permission":"cloudfunctions .functions.create","granted":true,"resourceAttributes":{}}],"resourceName":"projects/parkour-9136c/locations/us-central1/functions/makeUppercase","re​​quest":{"location ":"projects/parkour-9136c/locations/us-central1","@type":"type.googleapis.com/google.cloud.functions.v1.CreateFunctionRequest","function":{"labels":{"部署工具":"cli-firebase"},"entryPoint":"makeUppercase","eventTrigger":{"eventType":"providers/google.firebase.数据库/eventTypes/ref.write","re​​source":"projects/_/instances/parkour-9136c/refs/userfollowers/{pushId}/followers","service":"firebaseio.com"},"sourceUploadUrl": "https://storage.googleapis.com/gcf-upload-us-central1-f5adb7fe-7321-4f3c-8fe0-2b2307d26138/5b099ea8-161b-44a7-a3bd-18ce75c64859.zip?GoogleAccessId=service-807137615499@gcf-admin- robot.iam.gserviceaccount.com&Expires=1557824657&Signature=PJKzJsZtHWO1kIkmrSojpdgvb0jRzV91eNC9rZc4j%2FMcoHjILGm36FKCt6qQ2fxeAUu1%2FbrxpagdI7fHmUUUrDdTmnTNISr7FiN61sifUI%2B%2FGnUwo8SguzvrA7kADFqu8nD05FAo7BvG7biUrHmLgISlwo5dTKqcTSmExnaICA1tHYxjz%2Fk0RbmdGkcQ5HdeCKBnW0R7wQPsxswQyvR4cAU4WD2m3PPM9lncVr7pB%2Fh77FboGLi3sq%2FGHyEwUtjfUmyN9d%2FYUpKs48TMsGPknAGIvaFFUWQR23YCDUcrPipq1nW2W1JUdf5nGylYmVEeyF3jLrm%2BsOIcXiZ6LCRhpg%3D%3D ","name":"projects/parkour-9136c/locations/us- central1/functions/makeUppercase"}}}

解决办法是什么?谢谢

https://github.com/firebase/firebase-tools/issues/1317

标签: firebase-realtime-databasegoogle-cloud-functions

解决方案


在 Firebase 项目的 functions 文件夹中使用以下命令更新 Firebase CLI 和 SDK :

npm install firebase-functions@latest firebase-admin@latest --save
npm install -g firebase-tools

推荐阅读