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

Disabled support for node 22 in first-generation functions. An error occurs when deploying functions.

Open siarheidudko opened this issue 1 year ago • 27 comments

Related issues

[REQUIRED] Version info

node:

22.9.0

firebase-functions:

6.1.2

firebase-tools:

13.29.1

firebase-admin:

13.0.1

[REQUIRED] Test case

image

Node v22 support for 1st generation functions has disappeared.

[REQUIRED] Steps to reproduce

  1. Specify engines (node 22) in package.json:
"engines": {
    "node": "22"
  },
  1. Use the 1st and 2nd generation functions. (Some functions cannot be migrated to the 2nd generation at the moment, for example authentication triggers.)
  2. Just run command: firebase deploy -m "message" --only functions --force

[REQUIRED] Expected behavior

The functions should be deployed in the same way as it happened from August to November 2024. I have updated the engine from v20 to v22 in August 2024 image

[REQUIRED] Actual behavior

image image
{
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "status": {
      "code": 3,
      "message": "runtime: Runtime validation errors: [error_code: INVALID_RUNTIME\nmessage: \"Runtime \\\"nodejs22\\\" is not supported on GCF Gen1\"\n]"
    },
    "authenticationInfo": {
      "principalEmail": "[email protected]",
      "serviceAccountKeyName": "...",
      "principalSubject": "serviceAccount:[email protected]"
    },
    "requestMetadata": {
      "callerIp": "40.75.95.79",
      "callerSuppliedUserAgent": "FirebaseCLI/13.29.1,gzip(gfe),gzip(gfe)",
      "requestAttributes": {
        "time": "2024-12-14T11:08:18.672421Z",
        "auth": {}
      },
      "destinationAttributes": {}
    },
    "serviceName": "cloudfunctions.googleapis.com",
    "methodName": "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction",
    "authorizationInfo": [
      {
        "resource": "projects/ireceipt-pro/locations/us-central1/functions/triggers_auth_user_delete",
        "permission": "cloudfunctions.functions.update",
        "granted": true,
        "resourceAttributes": {},
        "permissionType": "ADMIN_WRITE"
      }
    ],
    "resourceName": "projects/ireceipt-pro/locations/us-central1/functions/triggers_auth_user_delete",
    "request": {
      "function": {
        "entryPoint": "triggers_auth_user_delete",
        "timeout": "60s",
        "name": "projects/ireceipt-pro/locations/us-central1/functions/triggers_auth_user_delete",
        "eventTrigger": {
          "resource": "projects/ireceipt-pro",
          "eventType": "providers/firebase.auth/eventTypes/user.delete"
        },
        "runtime": "nodejs22",
        "availableMemoryMb": 256,
        "labels": {
          "firebase-functions-hash": "b18866339b3181ec0aa270cdc97e69a4427c82f6",
          "deployment-tool": "cli-firebase"
        },
        "sourceUploadUrl": "...",
        "dockerRegistry": "ARTIFACT_REGISTRY"
      },
      "@type": "type.googleapis.com/google.cloud.functions.v1.UpdateFunctionRequest",
      "updateMask": "name,sourceUploadUrl,entryPoint,runtime,dockerRegistry,labels,eventTrigger.eventType,eventTrigger.resource,eventTrigger.failurePolicy,minInstances,maxInstances,ingressSettings,environmentVariables,serviceAccountEmail,availableMemoryMb,timeout,vpcConnector,vpcConnectorEgressSettings,sourceToken,buildEnvironmentVariables"
    },
    "resourceLocation": {
      "currentLocations": [
        "us-central1"
      ]
    }
  },
  "insertId": "mj9i9de25o2r",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "region": "us-central1",
      "function_name": "triggers_auth_user_delete",
      "project_id": "ireceipt-pro"
    }
  },
  "timestamp": "2024-12-14T11:08:18.513711Z",
  "severity": "ERROR",
  "logName": "projects/ireceipt-pro/logs/cloudaudit.googleapis.com%2Factivity",
  "receiveTimestamp": "2024-12-14T11:08:19.081159810Z"
}

Were you able to successfully deploy your functions?

No, this requires rolling back the platform to node v20.

siarheidudko avatar Dec 14 '24 11:12 siarheidudko

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Dec 14 '24 11:12 google-oss-bot

is there a workaround to change the runtime of a GCF Gen1 function to be node 20, while keeping the default for the project as node 22? or is the node version all or nothing change with the "engines" field

here is Firebase's documentation calling out that they specifically support both versions:

Note: Cloud Functions for Firebase (2nd gen) does not provide support for the events and triggers described in this guide. Because 1st gen and 2nd gen functions can coexist side-by-side in the same source file, you can still develop and deploy this functionality together with 2nd gen functions.

source

seemingly you CAN'T support both versions side-by-side if you choose to use Node 22, evidenced by this issue

seanblonien avatar Dec 18 '24 07:12 seanblonien

For those stuck on this, specify "nodejs20" as the Functions runtime in your firebase.json:

[
  "functions": [
    {
      "runtime": "nodejs20",
      // Other existing Functions config...
    }
  ],
  // Other existing firebase.json config...
]

You can find the relevant docs here.

For the Firebase team, it would be nice if the Gen1/2 Node versions moved in lockstep. Even better if Gen1 functions like the auth ones were just offered as Gen2 functions.

jwngr avatar Dec 24 '24 21:12 jwngr

@siarheidudko I had this same problem back in December. On a whim, I tried to deploy a v1 function with nodejs22 today, and it worked: Image

I'd love verification from the Firebase team that this won't change again. This still doesn't indicate v1 support.

kevin-induro avatar Jan 28 '25 21:01 kevin-induro

@kevin-induro my functions/package.json and libraries are all built to use "engines": { "node": "22" } and written in typescript - all my cloud functions are V2 except auth functions and are deployed to europe-west1. I have not specified any runtime in firebase.json.

Where did you specify your version of node for it to deploy successfully?

davie-robertson avatar May 07 '25 07:05 davie-robertson

@davie-robertson The issue here is with V1 functions, so you'd only have an issue with the auth functions if you're having an issue.

That said, I've continued to not see an issue despite the referenced documentation still not saying that V1 supports 22.

To answer your question, The only change I've made is to update the engine in the package.json to 22.

kevin-induro avatar May 07 '25 13:05 kevin-induro

Thanks @kevin-induro , I am aware for the V1 auth support and the docs stating node 22 isn't supported, but my functions are not deploying as yours are - I can only guess it's a region issue.

i  functions: updating Node.js 22 (1st Gen) function createUserDocument(europe-west1)...
i  functions: updating Node.js 22 (1st Gen) function deleteUserDocument(europe-west1)...
⚠  functions: failed to update function projects/MyProject/locations/europe-west1/functions/createUserDocument

davie-robertson avatar May 09 '25 17:05 davie-robertson

the current behaviour also contradicts this https://cloud.google.com/functions/docs/release-notes November 18, 2024 Cloud Run functions now supports the Node.js 22 runtime at the General Availability release level.

davie-robertson avatar May 09 '25 19:05 davie-robertson

and here's the real PITA, my function that won't deploy because it's using node 22, was previoulsy deployed using node 22:

firebase functions:delete createUserDocument --region=europe-west1 --force
i  functions: deleting Node.js 22 (1st Gen) function createUserDocument(europe-west1)...
✔  functions[createUserDocument(europe-west1)] Successful delete operation.
i  functions: cleaning up build files...

davie-robertson avatar May 10 '25 10:05 davie-robertson

We had an even more surprising behavior - deploys have been silently failing for us - firebase deploy runs successfully, gen1 functions on the web console are showing Node 22 runtime, but the actual deploy date and code is not updated. When running with --debug we see that there was an actual error:

Runtime validation errors: [error_code: INVALID_RUNTIME\nmessage: \"Runtime \\\"nodejs22\\\" is not supported on GCF Gen1\"\n]",
      "status": 400
    },
    "status": 400,
    "code": 400
  }

Even more bizzarre: We print process.version to our logs in the code and it is showing v22.15.0

So the runtime somehow updated, but the code is not updating.

isegal avatar May 16 '25 19:05 isegal

Same issue here, I have both Gen1 and Gen2 Cloud Functions within the same project. Currently, deploying the Gen1 functions fails with an error. Unfortunately, the error message provided during deployment isn't descriptive and doesn't mention the root cause. After checking the GCP logs, I discovered that the problem is related to Node 22.

Image

emaysyuk avatar May 25 '25 11:05 emaysyuk

Two months ago, we upgraded all our projects from Node.js 16 to 22 and updated Firebase Functions from v3.16.0 to v6.3.2. At that time, we intentionally avoided migrating to Gen2 since it requires renaming functions.

Today, I encountered a deployment failure on one of our projects with the following error:

:"Runtime validation errors: [error_code: INVALID_RUNTIME\nmessage: \"Runtime \\\"nodejs22\\\" is not supported on GCF Gen1\"\n]"}]}]}}

This project shares a codebase deployed to two Firebase environments—one for testing and one for production. Interestingly, the deployment succeeds for the testing environment but fails for production.

I verified the same issue in another project: its testing deployment fails with the same error, even though both projects use the similiar configuration.

This raises several questions:

  • Does Firebase Gen1 actually support Node.js 22?
  • If not, why was the deployment allowed initially?
  • Why is the behavior inconsistent across projects using the same setup?

fthdgn avatar May 28 '25 16:05 fthdgn

Hey @siarheidudko and all,

https://cloud.google.com/functions/docs/runtime-support#node.js

https://firebase.google.com/docs/functions/manage-functions?gen=1st#1g-set-runtime

As shown in the above, 1st generation functions do not support nodejs22. I'm not sure how some people are successfully deploying 1st gen functions using nodejs22 as a runtime, however, that's out of the scope of this repository.

Perhaps there should be a clear error when deploying with firebase-tools, so I've created a separate issue over there to hopefully provide clarity to people facing this issue when deploying.

Thanks for reporting this issue!

CorieW avatar Jun 04 '25 19:06 CorieW

@CorieW While a clear error is extremely welcome, I'm not sure that's enough. There are many people that have both v1 and v2 functions side by side, especially those using auth events which are very clearly unable to be v2 functions.

There is no solution for these being in the same codebase and we need one. I believe that's very much under the scope of this repository.

kevin-induro avatar Jun 04 '25 19:06 kevin-induro

@CorieW - After so many months of silence on the Firebase side, this response is pretty confusing. Many of us have been successfully deploying v1 functions deployed on node 22 for months now. See an example of a successful deploy here from yesterday:

i  functions: updating Node.js 22 (2nd Gen) function emitIntervalFeeds(us-central1)...
i  functions: updating Node.js 22 (2nd Gen) function handleFeedUnsubscribeOnUpdate(us-central1)...
i  functions: updating Node.js 22 (2nd Gen) function handleSuperfeedrWebhook(us-central1)...
i  functions: updating Node.js 22 (2nd Gen) function importFeedItemOnCreate(us-central1)...
i  functions: updating Node.js 22 (2nd Gen) function importFeedItemOnUpdate(us-central1)...
i  functions: updating Node.js 22 (1st Gen) function initializeAccountOnAuthCreate(us-central1)...
i  functions: updating Node.js 22 (2nd Gen) function subscribeToRssFeedOnCall(us-central1)...
i  functions: updating Node.js 22 (1st Gen) function wipeoutAccountOnAuthDelete(us-central1)...

Can you please make sure not to break those of us successfully deploying on node 22 with any new checks moving forward?

jwngr avatar Jun 04 '25 19:06 jwngr

@kevin-induro is firebase-functions/v2/identity not an option for you?

@jwngr interesting, I'll investigate this to see what's going on. Question: Can you deploy new v1 functions using a nodejs22 runtime? I wonder whether you deployed before the nodejs22 being restricted. Perhaps updates are allowed (to not break existing user projects), but new deployments are not.

CorieW avatar Jun 04 '25 20:06 CorieW

@CorieW I don't actually use those myself, personally, I was speaking from what others have brought up before and the fact that the linked page says

Cloud Functions for Firebase (2nd gen) does not provide support for the events and triggers described in this guide. Because 1st gen and 2nd gen functions can coexist side-by-side in the same source file, you can still develop and deploy this functionality together with 2nd gen functions.

If the linked page was wrong, let's update the documentation. Regardless, I do have other functions I have not migrated yet, but would still like to use side-by-side with v2 functions on nodejs22.

kevin-induro avatar Jun 04 '25 20:06 kevin-induro

@kevin-induro I'll raise this and see what I can get done about the wording. Perhaps it's worth referencing the auth identity stuff for v2.

CorieW avatar Jun 04 '25 21:06 CorieW

Can you deploy new v1 functions using a nodejs22 runtime?

Yeah, I added the initializeAccountOnAuthCreate one 4 days ago: https://github.com/jwngr/conductor/pull/276

is firebase-functions/v2/identity not an option for you?

Not for me. The auth functions are stuck on 1st gen only with no 2nd gen replacement. The identity functions do not have hooks for onCreateUser and onDeleteUser. So if I want to have a 1st gen auth function and a 2nd gen Firestore function, what am I supposed to do? Stay on Node 20 forever? Seems like the missing piece is Firebase offering 2nd gen auth functions that don't have the Node 20 limitation.

jwngr avatar Jun 04 '25 22:06 jwngr

We have 3 environments (dev, staging, and prod): we are able to deploy onUserCreate on the dev environment, but not on staging and prod. We're not sure why. So, this function definitely works on node 22 but for some reason deploys randomly.

Image

eli1stark avatar Jun 07 '25 20:06 eli1stark