Home > Blockchain >  "Cloud Functions API has not been used in project" when only using hosting
"Cloud Functions API has not been used in project" when only using hosting

Time:10-07

I initialized my project for hosting, using the firebase cli. I also let it automatically create the CI script for GitHub.

The configs look like this:

{
  "projects": {
    "default": "project-name"
  }
}
{
  "hosting": {
    "public": "dist",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
name: deploy on push
"on":
  push:
    branches:
      - main
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - run: yarn && yarn build
      - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_PROJECT_NAME }}"
          channelId: live
          projectId: project-name

But once the CI script runs on my actions I get the following error:

  [2022-10-06T15:45:17.926Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v1/projects/project-name/locations/-/functions ***"error":***"code":403,"message":"Cloud Functions API has not been used in project 123123123 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.","status":"PERMISSION_DENIED","details":[***"@type":"type.googleapis.com/google.rpc.Help","links":[***"description":"Google developers console API activation","url":"https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123"***]***,***"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"SERVICE_DISABLED","domain":"googleapis.com","metadata":***"service":"cloudfunctions.googleapis.com","consumer":"projects/123123123"***]***
  [2022-10-06T15:45:17.930Z] [functions] failed to list functions for project-name
  [2022-10-06T15:45:17.930Z] [functions] HTTP Error: 403, Cloud Functions API has not been used in project 123123123 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
  [2022-10-06T15:45:17.931Z] FirebaseError: HTTP Error: 403, Cloud Functions API has not been used in project 123123123 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudfunctions.googleapis.com/overview?project=123123123 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
      at responseToError (/home/runner/.npm/_npx/7750544ccf494d8b/node_modules/firebase-tools/lib/responseToError.js:49:12)
      at RetryOperation._fn (/home/runner/.npm/_npx/7750544ccf494d8b/node_modules/firebase-tools/lib/apiv2.js:288:77)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
  
  Error: Failed to list functions for project-name
  
  The process '/usr/local/bin/npx' failed with exit code 1
  Error: The process '/usr/local/bin/npx' failed with exit code 1

The thing is, I only want to use the hosting capabilities of firebase and have no plans of enabling firebase functions, so why does it require me to do so? I have created projects in the past, which did not have this requirement.

CodePudding user response:

Per the error, your script is calling two GitHub Actions and one of these is calling GET https://cloudfunctions.googleapis.com/v1/projects/{project}/locations/-/functions to list the Functions in the Project. This method requires the (cloudfunctions) service to be enabled.

  • Either enable the service in the project so that the call succeeds
  • Or remove the step in the script that makes the call.

CodePudding user response:

So it seems like it is a problem with the newest firebase-tools version. After downgrading from 11.14.0 to 11.13.0 locally, it worked again (which I recognized thanks to this comment).

So to make it run in CI, I just installed [email protected] as a dev-dependency directly into the project and CI ran through fine again.

  • Related