10

I have two Firebase hosting sites in >Firebase >Hosting >Main (https://console.firebase.google.com/u/0/project/example/hosting/main)

1. **foobar**.web.app (default project from setup process)
2. **example**.web.app (added as an additional web app under the main project and linked for hosting)

These are my .firebaserc settings:

 {
  "targets": {
    "foobar": {
      "hosting": {
        "foobar": [
          "foobarWebApp"
        ]
      }
    },
    "example": {
      "hosting": {
        "foobar": [
          "foobarWebApp"
        ],
        "example": [
          "foobar"
        ]
      }
    }
  },
  "projects": {
    "default": "foobar"
  }
}

After running firebase deploy from the Firebase CLI the files get deployed to foobar.web.app. How to change it to example.web.app?

I tried firebase deploy --only hosting:example but that always returns Error: An unexpected error has occurred.

Tom
  • 5,588
  • 20
  • 77
  • 129

3 Answers3

6

Have you set up the hosting target correctly?

In your CLI,

firebase target:apply type target-name resource-name

  • type — the relevant Firebase resource type. In your case, use hosting.
  • target-name — a unique identifier for the Hosting site that you're deploying to (can be anything)
  • resource-name — the name of the Hosting site as listed in your Firebase project, in your case foobar or example

After you've set up deploy targets for your Firebase resources, reference the applied target names in your firebase.json configuration file.

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

EDIT:

Your .firebaserc should look something like this, (although running that command line statement above should change this already for you, and all you need to update is the package.json):

"projects": {
    "default": "project-name"
},
"targets": {
    "project-name": {
        "hosting": {
            "example": [ // target-name
                "example-website" // resource-name
            ],
            "foobar": [ // target-name
                "foobar-website" // resource-name
            ]
        }
    }
}
Ryan
  • 720
  • 1
  • 8
  • 27
  • Thanks for your answer. I tried it but still getting the error. I added my firebaserc settings to my question. Are they correct? I only want to deploy to the child WebApp called "example" not to the parent called foobar. – Tom Apr 22 '20 at 15:19
  • 1
    I just edited my answer, assuming that both foobar and example domains are under the same project – Ryan Apr 23 '20 at 05:43
  • 1
    Thank you, it was the "hosting": {"site": "example", part that caused the issue – Tom Apr 23 '20 at 09:34
1

made sense to me to break it down into "definitive descriptive variables"

ex .firebaserc file

{
  "targets": {
    "firebaseProjectID": {
      "hosting": {
        "targetValueInFirebase.json": [
          "yourFirebaseHostingDomain"
        ]
      }
    }
  },
  "projects": {
    "cli_alias": "firebaseProjectID"
  }
}
Joe Code
  • 31
  • 2
0

I'm have same problem and solved it by this:

  • 1.delete browser cache , 2.reopen browser , 3.run deploy again 4.open Hosting URL in new private window*
Abd Nezar
  • 341
  • 4
  • 8