firebase-tools: Firebase Deploy fails for NextJs app with SSR - Failed to replace Run service

[REQUIRED] Environment info

12.4.0 (with webframeworks experimental feature enabled)

firebase-tools:

12.4.0

Platform:

macOS

[REQUIRED] Test case

  1. install firebase CLI
  2. firebase login
  3. firebase experiments:enable webframeworks
  4. firebase init hosting (and use pre-existing project)
  5. firebase deploy

Validate that deployment has succeeded.

[REQUIRED] Steps to reproduce

Pre-requisite: Existing NextJS project that requires SSR and Firebase project set up with billing enabled.

  1. install firebase CLI
  2. firebase login
  3. firebase experiments:enable webframeworks
  4. firebase init hosting (and use pre-existing project)
  5. firebase deploy

[REQUIRED] Expected behavior

Expect static files and functions for SSR to be deployed to firebase project

[REQUIRED] Actual behavior

Deployment step fails. SSR function seems to have been deployed but static site hosting has not and project hosting URL shows no site deployed. Console fail has the following output:

Error: Failed to replace Run service projects/…

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Haven’t had issues before (have deployed several dozen times prior), but it seems this become an issue now.

Debug showing:

{"error":{"code":400,"message":"spec.template.spec.runtimeClassName: When annotation [run.googleapis.com/base-images] set, runtimeClassName must be set to run.googleapis.com/linux-base-image-update","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"spec.template.spec.runtimeClassName","description":"When annotation [run.googleapis.com/base-images] set, runtimeClassName must be set to run.googleapis.com/linux-base-image-update"}]}]}}
[2024-04-25T19:06:52.895Z] FirebaseError: HTTP Error: 400, spec.template.spec.runtimeClassName: When annotation [run.googleapis.com/base-images] set, runtimeClassName must be set to run.googleapis.com/linux-base-image-update
    at responseToError (/Users/brandon/.nvm/versions/node/v20.11.1/lib/node_modules/firebase-tools/lib/responseToError.js:49:12)
    at RetryOperation._fn (/Users/brandon/.nvm/versions/node/v20.11.1/lib/node_modules/firebase-tools/lib/apiv2.js:299:77)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Your projects region is typically set when you create a firestore DB or cloud storage https://firebase.google.com/docs/firestore/locations

Well that’s not a project location. That’s just the location of the firestore database in your firebase project. Cloud storage and functions could and propably have different locations. Each service in your firebase project has a location that is independent from the other services location.

For example my firestore database is in eur3. My cloud storage bucket is in eu. Both are multi region locations. Functions and therefore the frameworksBackend can never be deployed in a multi region location like eur3. You have to choose one or multiple single region locations like europe-west1, europe-west2, europe-west3 etc for your function deployments. The documentation suggests to choose a regional location “near” the data location. But nobody is bound to that suggestion.

From the docs “There’s not a global project-level or app-level setting for location” -> https://firebase.google.com/docs/projects/locations

But you were right that the problem was related to the region of the SSR function and it’s working in some regions but not all. Aligning your frameworks backend region with your firestore database region was just a coincident and shouldn’t confuse others looking for a workaround.

Haven’t had issues before (have deployed several dozen times prior), but it seems this become an issue now.

Debug showing:

{"error":{"code":400,"message":"spec.template.spec.runtimeClassName: When annotation [run.googleapis.com/base-images] set, runtimeClassName must be set to run.googleapis.com/linux-base-image-update","status":"INVALID_ARGUMENT","details":[{"@type":"type.googleapis.com/google.rpc.BadRequest","fieldViolations":[{"field":"spec.template.spec.runtimeClassName","description":"When annotation [run.googleapis.com/base-images] set, runtimeClassName must be set to run.googleapis.com/linux-base-image-update"}]}]}}
[2024-04-25T19:06:52.895Z] FirebaseError: HTTP Error: 400, spec.template.spec.runtimeClassName: When annotation [run.googleapis.com/base-images] set, runtimeClassName must be set to run.googleapis.com/linux-base-image-update
    at responseToError (/Users/brandon/.nvm/versions/node/v20.11.1/lib/node_modules/firebase-tools/lib/responseToError.js:49:12)
    at RetryOperation._fn (/Users/brandon/.nvm/versions/node/v20.11.1/lib/node_modules/firebase-tools/lib/apiv2.js:299:77)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Since I had the same error with my nextjs deployment, I digged into the code and found some information (no solution so far) https://github.com/firebase/firebase-tools/issues/7054#issuecomment-2082143931

I tracked the issue for this down in GCP logs. For anyone else who might hit a similar problem it was due to the length of the Firebase project ID. Although the project ID itself was within the allowed limit the SSR functions that get created from this are prefixed with ‘ssr’ and then a random ID is appended so all of this was taking it beyond the 46 character limit supported and causing the deployment to fail.