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

[CF3v2 deploy on fresh project] TypeError: Cannot read properties of undefined (reading 'service') #5157

Closed
petrvecera opened this issue Oct 22, 2022 · 11 comments

Comments

@petrvecera
Copy link

I am unable to deploy brand new NextJS app as per https://firebase.google.com/docs/hosting/nextjs
I am getting "firebase" errors.

[REQUIRED] Environment info

firebase-tools: 11.15.0

Platform: Debian ( linux)

node: 16.18.2

[REQUIRED] Steps to reproduce

My steps:

Prepare project:

  • Create a brand new firebase project
  • Upgrade the project to the blaze plan

Repo:

  • run npm create-next-app
  • npm i firebase-tools
  • firebase experiments:enable webframeworks
  • firebase login
  • firebase init hosting - select the project
  • firebase deploy

[REQUIRED] Expected behavior

Project is deployed.

[REQUIRED] Actual behavior

On the first run i get:

Unable to retrieve the repository metadata for projects/fb-next-test-2/locations/us-central1/repositories/gcf-artifacts. Ensure that the Cloud Functions service account has 'artifactregistry.repositories.list' and 'artifactregistry.repositories.get' permissions. You can add the permissions by granting the role 'roles/artifactregistry.reader'.

Functions deploy had errors with the following functions:
        firebase-frameworks-fb-next-test-2:ssrfbnexttest2(us-central1)

On the second run:

[2022-10-22T17:43:43.502Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v2/projects/fb-next-test-2/locations/-/functions {"functions":[{"name":"projects/fb-next-test-2/locations/us-central1/functions/ssrfbnexttest2","buildConfig":{"runtime":"nodejs16","entryPoint":"ssr","source":{"storageSource":{"bucket":"gcf-v2-sources-708509435983-us-central1","object":"ssrfbnexttest2/function-source.zip"}},"sourceProvenance":{}},"state":"FAILED","updateTime":"2022-10-22T16:08:05.746209237Z","labels":{"deployment-tool":"cli-firebase","firebase-functions-codebase":"firebase-frameworks-fb-next-test-2","firebase-functions-hash":"0f18093bd84d11e039f31efd5ea46b21f2b4b3b5"},"stateMessages":[{"severity":"ERROR","type":"CloudRunServiceNotFound","message":"Cloud Run service projects/fb-next-test-2/locations/us-central1/services/ssrfbnexttest2 for the function was not found. The function will not work correctly. Please redeploy."}],"environment":"GEN_2"}]}
[2022-10-22T17:43:43.505Z] TypeError: Cannot read properties of undefined (reading 'service')
    at /usr/local/share/npm-global/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:198:113
    at Array.map (<anonymous>)
    at loadExistingBackend (/usr/local/share/npm-global/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:198:69)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.existingBackend (/usr/local/share/npm-global/lib/node_modules/firebase-tools/lib/deploy/functions/backend.js:174:9)
    at async prepare (/usr/local/share/npm-global/lib/node_modules/firebase-tools/lib/deploy/functions/prepare.js:138:115)
    at async chain (/usr/local/share/npm-global/lib/node_modules/firebase-tools/lib/deploy/index.js:35:9)
    at async deploy (/usr/local/share/npm-global/lib/node_modules/firebase-tools/lib/deploy/index.js:79:5)

Error: An unexpected error has occurred

I tried testing this both on local machine - M1 Mac - I run into weird nodejs errors.
Next I tried GitHub Codespaces. Repo is here https://github.com/vsb-js/next-fb-hosting

I am not sure what else I am getting wrong. I am sorry if this is my mistake. If anyone has boilerplate repo, where you just specify your FB project - that would be very helpful. Thank you

firebase-debug.log

@petrvecera petrvecera added the bug label Oct 22, 2022
@google-oss-bot
Copy link
Contributor

This issue does not seem to follow the issue template. Make sure you provide all the required information.

@mporracindie
Copy link

Im running into the same issue

@ghost
Copy link

ghost commented Oct 25, 2022

I am also facing the same issue.

@jamesdaniels jamesdaniels changed the title Unable to deploy new clean NextJS web app - Integrate Next.js [CF3v2 deploy on fresh project] TypeError: Cannot read properties of undefined (reading 'service') Oct 25, 2022
@jamesdaniels
Copy link
Member

It seems this is not isolated to web frameworks but appears to be a gen2 function deploy to a fresh project. A race condition in permission enablement seems likely, we're investigating.

There is a work around, delete the broken Cloud Function (for SSR + Image Optimization) in the Google Cloud Console. It is left in a bad state that cannot be recovered w/the current firebase-tools. After manual removal, your next deploy should work.

@ghost
Copy link

ghost commented Oct 25, 2022

@jamesdaniels
In my environment, deleting the Cloud Function with the Google Cloud Console does not solve it and the same error occurs, so I am in trouble because there is no workaround.

Thank you for investigating, I hope it will be resolved soon.

@petrvecera
Copy link
Author

The workaround worked for us. But we had to do the deploy twice. On first the SSR was returning 404, the second deploy worked as expected.

@ghost
Copy link

ghost commented Oct 26, 2022

@petrvecera
In my environment, I tried to delete the SSR function in Cloud Functions and redeploy it many times, but it was still unable to deploy.

@ghost
Copy link

ghost commented Oct 26, 2022

When I created and deployed a new Next.js app separately, it took a few minutes to deploy the SSR function of Cloud Functions, but I was able to deploy it

I don't know if it's because of Next.js 13,
I got the error Next.js requires React 18.2.0 to be installed.

    // Only error in first one compiler (client) once
    if (isClient) {
        if (!hasReactRoot) {
            throw new Error("Next.js requires React 18.2.0 to be installed.");
        }
    }

/node_modules/next/dist/build/webpack-config.js

I'm using React 18.12.0 properly, but I think it's probably a problem with Next.js settings.
Solved by writing __NEXT_REACT_ROOT='true' in the .env file.

@jamesdaniels
Copy link
Member

I have a work around with the Next 13 / React 18 bug in progress here #5175

@ghost
Copy link

ghost commented Oct 27, 2022

@jamesdaniels
Thank you, I appreciate the quick response.

@taeold
Copy link
Contributor

taeold commented Nov 2, 2022

I'm going to close this as duplicate of #4800.

Feel free to re-open if I'm mistaken.

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

5 participants