0

I am trying to test new functions locally.

Project file structure is:

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

Running: firebase serve --only functions from either App/ or functions/

returns: Error: HTTP Error: 400, Request contains an invalid argument.

Is this some kind of authentication error?

I downgraded from node@12 to node@8

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

I have made sure that my .bash_profile and .zshrc paths to node and npm are correct. I can post those files if it helps.

I've run firebase logout and then firebase login with no problems. I can access https://console.firebase.google.com with no problems.

I've quit terminal and reopened it after downgrading Node.

I've shut down and restarted my computer.

Project file structure is:

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

In 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": [
    ]
  }
}

In functions/ 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
}

Running firebase serve --only functions --debug Returns:

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

I am expecting to be able to call functions locally with http at localhost:5000. For example:

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

Instead I get Error: HTTP Error: 400, Request contains an invalid argument.

Can anyone see where I am going wrong?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
skillit zimberg
  • 1,024
  • 1
  • 14
  • 22
  • Please edit the question to include the [MCVE](https://stackoverflow.com/help/minimal-reproducible-example) for the code you're trying to run. – Doug Stevenson Oct 23 '19 at 09:23
  • @DougStevenson, I have been failing on trying to create an MCVE all morning. But an interesting thing that I've discovered along the way is that GCloud and/or Cloud IAM is somehow using the first word of the project name, not the project ID. I'm trying to figure out why that's happening. I created another project that works as expected, including GCloud and Cloud IAM. – skillit zimberg Oct 23 '19 at 19:38

1 Answers1

3

Running firebase serve --only functions --debug showed that the first word of the project name was being used to check permissions, instead of the project ID.

The solution in my case was to run gcloud components update, firebase logout, firebase login, then firebase use [projectID].

I don't know that logging out and in was necessary, but I was trying to cover all bases.

skillit zimberg
  • 1,024
  • 1
  • 14
  • 22