为什么“ firebase服务”错误和“ HTTP错误:400,请求包含无效参数”?

时间:2019-10-23 02:29:32

标签: node.js firebase google-cloud-firestore google-cloud-functions firebase-cli

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

项目文件结构为:

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

运行: {/ {1}}来自App /或functions /

返回: firebase serve --only functions

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

我从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的{​​{1}}和.zshrc路径正确。如果有帮助,我可以发布这些文件。

我先运行node,然后再运行npm都没有问题。我可以毫无问题地访问firebase logout

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

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

项目文件结构为:

firebase login

在App / firebase.json:

https://console.firebase.google.com

在功能/ package.json:

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

运行{ "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": [ ] } } 返回:

{
  "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
}

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

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" } } }

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

1 个答案:

答案 0 :(得分:0)

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

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

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