firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Undeleteable function with `TypeError: Cannot read properties of undefined (reading 'service')`

Open ky28059 opened this issue 3 years ago • 3 comments

[REQUIRED] Environment info

firebase-tools: 11.3.0

Platform: Windows

[REQUIRED] Test case

Possibly related to #4770.

I upgraded a function from v1 to v2 and tried to deploy it, but the deploy failed with Error: Pass the --force option to deploy functions that increase the minimum bill. However, the function was created on Firebase without a trigger, and all subsequent attempts to redeploy, even after downgrading the function to v1, fail with Error: An unexpected error has occurred.. Running with --debug gives:

[2022-07-31T21:45:23.477Z] >>> [apiv2][query] GET https://cloudfunctions.googleapis.com/v2alpha/projects/gunnwatt/locations/-/functions [none]
[2022-07-31T21:45:24.205Z] <<< [apiv2][status] GET https://cloudfunctions.googleapis.com/v2alpha/projects/gunnwatt/locations/-/functions 200
[2022-07-31T21:45:24.206Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v2alpha/projects/gunnwatt/locations/-/functions {"functions":[{"name":"projects/gunnwatt/locations/us-central1/functions/api","buildConfig":{"build":"projects/108805079121/locations/us-central1/builds/51bcc649-8ec1-4e2b-af37-5d8c1ca3b4ec","runtime":"nodejs14","entryPoint":"api","source":{"storageSource":{"bucket":"gcf-v2-sources-108805079121-us-central1","object":"api/function-source.zip"}},"sourceProvenance":{"resolvedStorageSource":{"bucket":"gcf-v2-sources-108805079121-us-central1","object":"api/function-source.zip","generation":"1659293271683162"}}},"state":"FAILED","updateTime":"2022-07-31T18:49:52.861395303Z","labels":{"deployment-tool":"cli-firebase"},"stateMessages":[{"severity":"ERROR","type":"CloudRunServiceNotFound","message":"Cloud Run service projects/gunnwatt/locations/us-central1/services/api for the function was not found. The function will not work correctly. Please redeploy."}],"environment":"GEN_2"}]}
[2022-07-31T21:45:24.368Z] TypeError: Cannot read properties of undefined (reading 'service')
    at C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\backend.js:197:113
    at Array.map (<anonymous>)
    at loadExistingBackend (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\backend.js:197:69)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.existingBackend (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\functions\backend.js:173:9)
    at async Promise.all (index 1)
    at async Command.actionFn (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\commands\functions-delete.js:34:39)

Error: An unexpected error has occurred.

image

The function cannot be deleted using the Firebase console and all attempts to redeploy or do firebase functions:delete api are met with the above error, essentially soft locking deployment.

image

[REQUIRED] Steps to reproduce

Run

firebase deploy --only functions

with the above configuration of v1 and v2 functions.

[REQUIRED] Expected behavior

Reverting to a v1 function should resolve deployment issues.

[REQUIRED] Actual behavior

The deploy still fails.

ky28059 avatar Jul 31 '22 22:07 ky28059

Having the same issue – can't do anything with my functions

mb8z avatar Aug 02 '22 15:08 mb8z

Sorry for the troubles @Ancinek @ky28059. I think I have a hunch on what's going on here and will see if I can a fix out.

In the meantime, I think a workaround is to visit https://console.cloud.google.com/functions/list and delete the problematic function manually.

taeold avatar Aug 02 '22 16:08 taeold

Yes, can confirm that deleting those from the Google Cloud Console worked like charm and I didn't have any issue deploying the function after that!

mb8z avatar Aug 02 '22 20:08 mb8z

Sorry for the troubles @Ancinek @ky28059. I think I have a hunch on what's going on here and will see if I can a fix out.

In the meantime, I think a workaround is to visit https://console.cloud.google.com/functions/list and delete the problematic function manually.

Undeleteable function isn't showing on google cloud console for me, shows in firebase functions as 'cannot delete' - v2 function seems to be a limbo state

[debug] [2022-10-17T00:48:00.466Z] TypeError: Cannot read properties of undefined (reading 'service') at /Users/tom/Library/pnpm/global/5/.pnpm/[email protected]/node_modules/firebase-tools/lib/deploy/functions/backend.js:198:113

jabza avatar Oct 17 '22 00:10 jabza

Any update with this? I think this is problem when failed to deploy cloud functions v2. There are no serviceConfig property for it.

Example :

{
  "name": "projects/<PROJECT_ID>locations/us-central1/functions/<FUNCTION_ID>",
  "buildConfig": {
    "build": "projects/<PROJECT_ID>/locations/us-central1/builds/75e6c15a-ac12-40fc-a155-4631c7d69085",
    "runtime": "nodejs16",
    "entryPoint": "<FUNCTION_ID>",
    "source": {
      "storageSource": {
        "bucket": "gcf-v2-sources-<PROJECT_ID>-us-central1",
        "object": "<FUNCTION_ID>/function-source.zip"
      }
    },
    "sourceProvenance": {
      "resolvedStorageSource": {
        "bucket": "gcf-v2-sources-<PROJECT_ID>-us-central1",
        "object": "<FUNCTION_ID>/function-source.zip",
        "generation": "1669184567266545"
      }
    }
  },
  "state": "FAILED",
  "updateTime": "2022-11-23T06:24:04.959406278Z",
  "labels": {
    "deployment-tool": "cli-gcloud"
  },
  "stateMessages": [
    {
      "severity": "ERROR",
      "type": "CloudRunServiceNotFound",
      "message": "Cloud Run service projects/<PROJECT_ID>/locations/us-central1/services/<FUNCTION_ID> for the function was not found. The function will not work correctly. Please redeploy."
    }
  ],
  "environment": "GEN_2"
}

superwoou avatar Nov 23 '22 06:11 superwoou

@taeold I can confirm that deleting the wrong deployed v2 function from gcp console solved the problem

AnthonyNahas avatar Jan 02 '23 00:01 AnthonyNahas

I had same issue. I solved it by deploying a dummy Cloud Run Service with problematic function name.

soultoru avatar Jan 23 '23 18:01 soultoru