为什么`firebase serve`错误,`HTTP错误:400,请求包含无效参数?

问题描述 投票:0回答:1

我正在尝试在本地测试新功能。

项目文件结构为:

App/
   typescript_functions/
   flutter_web_app/
   .firebaserc
   firebase.json
   firestore.indexes.json
   firestore.rules

正在运行:firebase serve --only functions来自App /或功能/

返回:Error: HTTP Error: 400, Request contains an invalid argument.

这是某种身份验证错误吗?

我从node@12降级为node@8

node -v
v8.16.2
npm -v
6.4.1
firebase --version
7.6.1

我已经确定我到.bash_profile.zshrcnodenpm路径正确。如果有帮助,我可以发布这些文件。

我已经运行了firebase logout,然后没有问题地运行了firebase login。我可以毫无问题地访问https://console.firebase.google.com

我退出终端并在降级Node之后重新打开它。

我已经关闭并重新启动计算机。

项目文件结构为:

App/
   typescript_functions/
   flutter_web_app/
   .firebaserc
   firebase.json
   firestore.indexes.json
   firestore.rules

在App中/firebase.json:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  },
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
    ]
  }
}

在功能/package.json:

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "main": "lib/index.js",
  "dependencies": {
    "@types/puppeteer": "^1.20.2",
    "algoliasearch": "^3.35.0",
    "axios": "^0.19.0",
    "dotenv": "^8.2.0",
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.1.0",
    "puppeteer": "^1.20.0"
  },
  "devDependencies": {
    "@types/algoliasearch": "^3.34.3",
    "@types/dotenv": "^6.1.1",
    "jest-puppeteer": "^4.3.0",
    "tslint": "^5.12.0",
    "typescript": "^3.2.2"
  },
  "private": true
}

正在运行firebase serve --only functions --debug返回:

[2019-10-23T02:06:29.461Z] ----------------------------------------------------------------------
[2019-10-23T02:06:29.464Z] Command:       /usr/local/Cellar/node@8/8.16.2/bin/node /usr/local/bin/firebase serve --only functions --debug
[2019-10-23T02:06:29.465Z] CLI Version:   7.6.1
[2019-10-23T02:06:29.465Z] Platform:      darwin
[2019-10-23T02:06:29.465Z] Node Version:  v8.16.2
[2019-10-23T02:06:29.465Z] Time:          Tue Oct 22 2019 19:06:29 GMT-0700 (PDT)
[2019-10-23T02:06:29.465Z] ----------------------------------------------------------------------
[2019-10-23T02:06:29.466Z] 
[2019-10-23T02:06:29.473Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2019-10-23T02:06:29.474Z] > authorizing via signed-in user
[2019-10-23T02:06:29.474Z] [iam] checking project [PROJECT] for permissions ["firebase.projects.get"]
[2019-10-23T02:06:29.476Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/[PROJECT]:testIamPermissions  
 permissions=[firebase.projects.get]
[2019-10-23T02:06:29.609Z] <<< HTTP RESPONSE 400 vary=X-Origin, Referer, Origin,Accept-Encoding, content-type=application/json; charset=UTF-8, date=Wed, 23 Oct 2019 02:06:29 GMT, server=ESF, cache-control=private, x-xss-protection=0, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, server-timing=gfet4t7; dur=59, alt-svc=quic=":443"; ma=2592000; v="46,43",h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000, accept-ranges=none, transfer-encoding=chunked
[2019-10-23T02:06:29.610Z] <<< HTTP RESPONSE BODY code=400, message=Request contains an invalid argument., status=INVALID_ARGUMENT

Error: HTTP Error: 400, Request contains an invalid argument.
[2019-10-23T02:06:29.673Z] Error Context: {
  "body": {
    "error": {
      "code": 400,
      "message": "Request contains an invalid argument.",
      "status": "INVALID_ARGUMENT"
    }
  },
  "response": {
    "statusCode": 400,
    "body": {
      "error": {
        "code": 400,
        "message": "Request contains an invalid argument.",
        "status": "INVALID_ARGUMENT"
      }
    },
    "headers": {
      "vary": "X-Origin, Referer, Origin,Accept-Encoding",
      "content-type": "application/json; charset=UTF-8",
      "date": "Wed, 23 Oct 2019 02:06:29 GMT",
      "server": "ESF",
      "cache-control": "private",
      "x-xss-protection": "0",
      "x-frame-options": "SAMEORIGIN",
      "x-content-type-options": "nosniff",
      "server-timing": "gfet4t7; dur=59",
      "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,43\",h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000",
      "accept-ranges": "none",
      "transfer-encoding": "chunked"
    },
    "request": {
      "uri": {
        "protocol": "https:",
        "slashes": true,
        "auth": null,
        "host": "cloudresourcemanager.googleapis.com",
        "port": 443,
        "hostname": "cloudresourcemanager.googleapis.com",
        "hash": null,
        "search": null,
        "query": null,
        "pathname": "/v1/projects/[PROJECT]:testIamPermissions",
        "path": "/v1/projects/[PROJECT]:testIamPermissions",
        "href": "https://cloudresourcemanager.googleapis.com/v1/projects/[PROJECT]:testIamPermissions"
      },
      "method": "POST"
    }
  }
}

我希望能够使用localhost:5000上的http在本地调用函数。例如:

curl "http://localhost:5000/project-name/us-central1/runMyFunction?someDocumentId=some-someDocumentId-hash&anotherDocumentId=some-anotherDocumentId-hash"

相反,我得到了Error: HTTP Error: 400, Request contains an invalid argument.

谁能看到我要去哪里了吗?

node.js firebase google-cloud-firestore google-cloud-functions firebase-cli
1个回答
0
投票

正在运行firebase serve --only functions --debug显示项目名称的第一个单词用于检查权限,而不是项目ID。

在我的情况下,解决方案是先运行gcloud components updatefirebase logoutfirebase login,然后运行firebase use [projectID]

我不知道注销和登录是必需的,但是我试图涵盖所有基础。

© www.soinside.com 2019 - 2024. All rights reserved.