Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Deploy fails for NextJs app with SSR - Failed to replace Run service #6020

Closed
Rich-Akcelo opened this issue Jun 22, 2023 · 15 comments
Closed

Comments

@Rich-Akcelo
Copy link

Rich-Akcelo commented Jun 22, 2023

[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/...

@google-oss-bot
Copy link
Contributor

This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.

@Rich-Akcelo
Copy link
Author

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.

@mirco123
Copy link

so what is the solution as of now?

@Rich-Akcelo
Copy link
Author

Using a shorter Firebase project ID was the only way I was able to get this to work.

@vojdan
Copy link

vojdan commented Oct 6, 2023

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.

Thanks! This worked.

@leeprobert
Copy link

What worked here? There's nothing that can be done. You can't change the ID and even if I did, the path is still too long.

@brh55
Copy link

brh55 commented Apr 25, 2024

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)

@baileykyle
Copy link

In case anyone else has this issue: I resolved it by changing the hosting region in my firebase.config to match the project

@brh55
Copy link

brh55 commented Apr 26, 2024

@baileykyle worked 🙇 , previously I had migrated to a newer firebase project for the purpose of switching regions, missed it in the config. Though, I'm still surprised that my deploys were working the last few weeks.

@benediktarnold
Copy link

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) #7054 (comment)

@drgarbage
Copy link

I have same issue as @benediktarnold mentioned. Is there any workaround?

@krismkt2013
Copy link

In case anyone else has this issue: I resolved it by changing the hosting region in my firebase.config to match the project

@baileykyle
Can you please specify the region you're using to solve this issue? 🙇

@benediktarnold
Copy link

In case anyone else has this issue: I resolved it by changing the hosting region in my firebase.config to match the project

@baileykyle Can you please specify the region you're using to solve this issue? 🙇

Since there is no such thing as a firebase project region the sentence "changing the hosting region in my firebase.config to match the project" didn't make any sense to me initially. But anyway: I played around a bit and changed the frameworksBackend region from europe-west3 to us-central1 (all my other functions are still in europe-west3) the deployment now works.

@baileykyle
Copy link

baileykyle commented Apr 29, 2024 via email

@benediktarnold
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants