Firebase-tools: Cannot read property 'deploys' of undefined

Created on 1 May 2019  ·  36Comments  ·  Source: firebase/firebase-tools

Environment info


firebase-tools:
[email protected]


Platform:
MacOS

Test case

MacOS, Node 10.15.3, [email protected]

Steps to reproduce

Create two hosting sites on firebase console.
Run
'firebase target:apply hosting dev firebase-hosting-id'
Run
'firebase deploy --only hosting:dev'

Expected behavior

Deployment successful

Actual behavior

[info] Project Console: https://console.firebase.google.com/project/project-name/overview
[debug] [2019-05-01T19:12:12.726Z] TypeError: Cannot read property 'deploys' of undefined
    at /Users/reeda/.nvm/versions/node/v10.15.3/lib/node_modules/firebase-tools/lib/deploy/index.js:88:36
    at process._tickCallback (internal/process/next_tick.js:68:7)
[error] 
[error] Error: An unexpected error has occurred.
hosting bug

Most helpful comment

I solved mine by making sure:

  1. .firebaserc must have targets.<PROJECT_ID>.hosting.<TARGET_NAME> = [ "<HOST_ID" ]
{
  "projects": {
    "default": "my-project-id"
  },
  "targets": {
    "my-project-id": {
      "hosting": {
        "my-blog": [
          "my-blog-host-id"
        ]
      }
    }
  }
}

The targets part can be generated using command firebase target:apply hosting my-blog my-blog-host-id

  1. firebase.json must have hosting as an array, and its item must have target: <TARGET_NAME>
{
  "hosting": [{
    "target": "my-blog",
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }]
}

The important part is making hosting an array, and add target to its item.

All 36 comments

There's been some adjustments in this flow recently. This error is coming from (in the source): https://github.com/firebase/firebase-tools/blob/master/src/deploy/index.js#L111

@Memeriaj can you take a look as you've been dealing with this lately?

I think I may know what is going on here. Does your firebase.json config file have "target": "dev" in it? I believe that we filtered out all of the configs that didn't match hosintg:dev and we were left with an empty array. We then went through all of the deploy steps for that empty array, effectively doing nothing. Then at the end we display the console link and the link to your newly deployed Hosting Site, which is where this error pops up because we didn't actually deploy anything.

We definitely need a proper error in this case explaining that we're not deploying anything.

(unrelated to the issue: generally you want to have your environment level switching be on a Firebase project level basis and not on different Hosting Sites within the same project (though you might have a Site for a blog, a Site for a web app, and a Site for your Docs that are all in the same environment on different Hosting Sites on the same project). This is mainly because things like Firebase Auth have only a single instance within a project. Ideally your firebase.json file is set up in such a way that you'd be able to something like firebase use dev, firebase deploy, check dev to make sure things are working, firebase use staging, firebase deploy, ...)

{ "firestore": { "rules": "firestore.rules", "indexes": "firestore.indexes.json" }, "hosting": { "public": "build", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "rewrites": [ { "source": "**", "destination": "/index.html" } ] }, "functions": { "predeploy": [ "npm --prefix \"$RESOURCE_DIR\" run lint" ] } }

I think the config you mention is in the firebase bashrc file and not the firebase json file.

Under the hosting section of the firebase.json file you need to have "target": "dev" in order for firebase deploy --only hosting:dev to work. The --only flag works like a filter and without the target field in your Hosting configuration then the CLI is not deploying anything (which should be an error with a useful message, but right now just blindly accepts it).

Sorry, its not clear where in the json to put the target field, would i put this at the root of the json(it didnt work) or should it be in the root of the hosting(also didnt work for me).

Also my firebaserc file, references my root project but it doesnt have any reference to the my second hosting site, so im not sure how the CLI tool will be able to understand where to deploy to.

It should go in the Hosting section of your firebase.json file so it would look something like:

{
// ...
  "hosting": [{ // Can be an array and have multiple configs, or an object if you've only got a single config
    "target": "blog",
    "public": "build/blog"
    // ...
  }],
// ...
}

This docs page has goes into further detail about each step and talks a little bit about why you might use targets and multiple Sites as well.

With firebase target:apply hosting dev firebase-hosting-id then firebase-hosting-id should be the Site name that you're planning on deploying to. This sets the target up on the project that you're currently on in the CLI, which is from the firebase use command. But maybe I misunderstood what you are trying to accomplish.

Thanks, i seem to making some headway but now im getting a 404 error entity not found.
So say my project in firebase is reedy-1 and my target is reedy-1-api
When i add my target in hosting as reedy-1-api, when i try to deploy it, it complains the entity was not found.
I can see in my firebaserc file, under targets

"targets": {
   "reedy-1": {
      "hosting": {
         "dev-api": [
           "reedy-1-api"
         ]
      }
   }
}

That snippet from your .firebaserc file looks correct to me.

Possible problems (you've probably checked these, but I'm listing them just in case other people stumble on to this later):

  • Make sure that you're using the proper project with firebase use
  • Make sure that the project ID is correct (this should be done for you via the project list in firebase use --add)
  • Make sure that the Site name is correct (easily found via <site-name>.firebaseapp.com)

If you try deploying with the debug flag on which part is the one returning the 404? I'd suspect that it would come from POST https://firebasehosting.googleapis.com/v1beta1/sites/<site-name>/versions since that is the first request of the actual Hosting deploy. If that is the case then I'd think that there is something wrong with the Site name you've set up as the target. If it is a request before that then my best guess is that there is something up with your project.

Ok, managed to work out what was going on.
You need a better error message for this too, so IF you are not on blaze and above, the error message is a 404, it's not obvious that i could not deploy because of my price plan.
After upgrading, boom, all is working.
Thanks for the help, happy to have this issue closed.

Whoa, wait. You needed to upgrade to Blaze for your deploy to work? What this because you hadn't created the new Hosting Site yet and needed to upgrade to do so? Or was it that you'd previously upgraded to Blaze, created a second Hosting Site, downgraded your billing plan, and then tried to deploy?

Also do you happen to know which request was throwing that error? Because you're right, that error is not helpful at all and I want to track down where it came from so that I can have it provide some guidance on what to do instead of some generic 404 text.

Yep thats right, Its a little confusing, I'm pretty sure i created the second site on the free tier, then i had problems deploying and thought it might be that, so i upgraded. When i realised i needed to raise an issue on github, i downgraded, when i did this, wierd things started happening in the firebase web console. The second hosting website would appear, but when i clicked it, it would show an empty screen.
After i received your support, i then tried to deploy, it showed a 404 on the deploy. So i thought i would upgrade back to blaze, and like magic it worked.

having same issue

@isevcik really? I was fairly certain that we fixed that issue (and I really should have closed this). Did you do a similar thing of upgrading your project, and then downgrading it?

You probably should email into support so that we can get the details of your project and get it fixed. You should make sure to mention this GitHub issue and me so that they know who to send it to.

@isevcik I was getting this same error and thought I had the same issue but it turned out to be a typo in the projectid in .firebaserc.
I used this command to add these targets rather than doing it manually and it worked.
Note: You also have to add the target to the firebase.json.

firebase target:apply type target-name resource-name

https://firebase.google.com/docs/cli/targets

Hello, same issue:

[debug] [2019-08-09T17:34:19.322Z] TypeError: Cannot read property 'deploys' of undefined
    at /Users/kevinliu/.npm-global/lib/node_modules/firebase-tools/lib/deploy/index.js:84:36
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
[error] 
[error] Error: An unexpected error has occurred.

index.js:

   if (deployedHosting) {
            _.each(context.hosting.deploys, function (deploy) {
                logger.info(clc.bold("Hosting URL:"), utils.addSubdomain(api.hostingOrigin, deploy.site));
            });
            const versionNames = context.hosting.deploys.map((deploy) => deploy.version);
            return { hosting: versionNames.length === 1 ? versionNames[0] : versionNames };
        }

@hpoit I'm also getting that error. Did you resolve it? If so what did you change?

[debug] [2019-08-16T18:44:01.159Z] TypeError: Cannot read property 'deploys' of undefined
    at C:\Users\Kraken\AppData\Roaming\npm\node_modules\firebase-tools\lib\deploy\index.js:84:36
    at process._tickCallback (internal/process/next_tick.js:68:7)
[error] 
[error] Error: An unexpected error has occurred.

Has this been resolved for anyone that's contacted support as @Memeriaj suggested? If so could the details be posted here for future reference?

@MaxInertia yes I resolved it, I formatted and erased my entire machine :-)

I think it just throws this error when it can't find the deploy target in your config. I would check your config in the two config firebase files. Post the contents up here if you want a second opinion.

Same thing here, when tried to deploy secondary website with firebase 7.3.1

Actually, error was in firebase.json, I have specified wrong "target"

I was able to resolve this issue by creating a new deploy target with the help of this guide:

https://firebase.google.com/docs/hosting/multisites?authuser=1#set_up_deploy_targets

I issued one command:

firebase target:apply hosting blog myapp

and added target key to my firebase.json

{
  "hosting": {
    "target": "myapp",
    ...
  }
  ...
}

edit: I stepped into this issue when I set up my first hosting on my brand new firebase project.

I was able to resolve it as well. My issue was that when I created my deploy target using the command outlined in the docs: $firebase target:apply hosting target-name resource-name, I had put my main project as the resource name. I changed that in the .firebaserc file and ran the firebase deploy command and it worked. Example below:

"targets": {
    "firebase-project-name": {
      "hosting": {
        "admin": [
          "admin-project"
        ]
      }
    }
  }

Hi am also facing the same issue, slightly in a different way(for custom added domain)

I am able to deploy into multiple hosting with different target name. but when I try to deploy into my custom added domain. I get Error: HTTP Error: 404, Requested entity was not found.

My custom domain is 3dprinter.froozen.in (added to firebase inside default hosting by clicking add custom domain button)
My custom domain is added inside my project default domain.
Kindly help me in proceeding further

We will need debug logs showing the exact failing call to be able to help
diagnose the issue.

On Sat, Jan 4, 2020, 12:52 AM nandha notifications@github.com wrote:

Hi am also facing the same issue, slightly in a different way(for custom
added domain)

I am able to deploy into multiple hosting with different target name. but
when I try to deploy into my custom added domain. I get Error: HTTP
Error: 404, Requested entity was not found.

My custom domain is 3dprinter.froozen.in (added to firebase inside
default hosting by clicking add custom domain button)
My custom domain is added inside my project default domain.
Kindly help me in proceeding further


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/1232?email_source=notifications&email_token=AAAAH7SNCPUEIMIWCDHK6CDQ4BE4JA5CNFSM4HJWK5J2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEICTYYY#issuecomment-570768483,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAAH7V26G3YF6Q7FYDP5QTQ4BE4JANCNFSM4HJWK5JQ
.

Hi @mbleigh ,

I got my issue resolved

  1. Domain was not fully linked
  2. Firebase.json of hosting was modified as per documentation
    When both are done, it worked properly as expected

If there is no more queries we can close this issue
In case of having queries please comment below

My problem with "Error: HTTP Error: 404, Requested entity was not found" i tried to use

```
"targets": {
"projectname": {
"hosting": {
"dev": [
"dev.site.com"
],
"prod": [
"site.com"
]
}
}
}


istead of

 ```
"targets": {
    "projectname": {
      "hosting": {
        "dev": [
          "dev-site-name"
        ],
        "prod": [
          "ez-site-name"
        ]
      }
    }
  }

I solved mine by making sure:

  1. .firebaserc must have targets.<PROJECT_ID>.hosting.<TARGET_NAME> = [ "<HOST_ID" ]
{
  "projects": {
    "default": "my-project-id"
  },
  "targets": {
    "my-project-id": {
      "hosting": {
        "my-blog": [
          "my-blog-host-id"
        ]
      }
    }
  }
}

The targets part can be generated using command firebase target:apply hosting my-blog my-blog-host-id

  1. firebase.json must have hosting as an array, and its item must have target: <TARGET_NAME>
{
  "hosting": [{
    "target": "my-blog",
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }]
}

The important part is making hosting an array, and add target to its item.

I got hit by this today as well, converting firebase.json hosting to array is really painful!

Now I need to duplicate every entry (even if its the same except target), that have lots of headers configuration for all environments, suddenly that's 4x json configuration I need to manage.

Anyway to reuse default hosting from firebase json?

Multiple sites in the same project are not intended to be used as "environments" -- if you have a "staging", "dev", etc site those should be sites in different projects and the firebase use command can help you switch between / deploy to them independently.

If that's not what you're doing, can you help me understand why the firebase.json config for each of the sites in your project are identical?

Well, that does pretty much sums it up, we current have 4 different env in different GCP projects, however we needed to deploy a temporary env (that includes other parts, not just firebase hosting), felt a lot simpler to re-use existing GCP project for a month or two, rather than adding a brand new one.

The only way to achieve this atm, is by duplicated firebase.json hosting configuration 5 times and adding unique target to each config.

I guess where the confusion comes from, is if you have default hosting configuration, expectation would be that it will work with any target or project, but I guess that's my misunderstand on how its used by different projects, compared to project + target.

Obviously can still make it work, just took a a while understand why this error showed up.
2020-06-22T17:20:39.837Z] TypeError: Cannot read property 'deploys' of undefined

The error message is definitely bad either way, and FWIW we have a better solution for "ephemeral previews" under development now 😄

Just to add to the "array fix", we have two sites deployed, I was able to target the correct site after changing targets to an array:

{ "hosting": [ { "target": "web", "public": "public", "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], "rewrites": [ { "source": "**", "destination": "/index.html" } ] }, { "target": "admin", "public": "build", "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], "rewrites": [ { "source": "**", "destination": "/index.html" } ] } ] }

But then the "admin" returned a blank page, as we are using React, the trick was to have the Public point to Build.
"public": "build",

I'm encountering this issue, and everything is correct according to the above and docs. Yet I still get the error. No matter which target I use, it doesn't seem to respect that, even though all the files and settings are reported as correct. Is there anything else not covered above?

  1. run : firebase target:apply hosting second-project-id second-project-id

  2. then open .firebaserc file and make sure it looks the following
    `{
    "targets": {

    "main-project-id": {
    "hosting": {
    "second-project-id": [
    "second-project-id"
    ]
    }
    }
    }
    }`

  3. then open firebase.json file and make sure it have the following
    "target": "second-project-id",

Hmm, I don't know exactly what I did to make it work, but it currently works with this .firebaserc:

{
  "projects": {
    "default": "mainProjectId"
  },
  "targets": {
    "mainProjectId": {
      "hosting": {
        "production": [
          "mainProjectId"
        ],
        "staging": [
          "secondProjectId"
        ]
      }
    }
  }
}
Was this page helpful?
0 / 5 - 0 ratings