Firebase-tools: Firebase deploy error message with an empty firebase.json

Created on 7 Jun 2017  ·  32Comments  ·  Source: firebase/firebase-tools

I was doing a bit of project merging today and came across an error with the firebase deploy command.

I accidentally left my firebase.json with the contents as:
{}

And was trying to deploy with firebase deploy --only database but was getting the following error:
Error: No targets found. Valid targets are: database,storage,functions,hosting

It took me awhile to figure out, as I thought this was linked with the recent nodejs v8 issues + the fact that I've been successfully deploying multiple projects for the last 6 months (rules and a separate functions project which had the empty firebase.json) until now.

If the error suggested looking into my firebase.json it would have helped 👍

Most helpful comment

I came here to open some issue similar to this one.

IMO it would be better to pre-populate the firebase with the default options. I choose that I wanted to use only hosting the firebase.json should have be created with the default hosting option.

{
  "hosting": {
    "public": "public"
  }
}

All 32 comments

I came here to open some issue similar to this one.

IMO it would be better to pre-populate the firebase with the default options. I choose that I wanted to use only hosting the firebase.json should have be created with the default hosting option.

{
  "hosting": {
    "public": "public"
  }
}

Thanks for the feedback @ahaverty ! I agree that the error msg could be a bit more descriptive. It is a bit difficult since the same error also occurs if someone misspelled target names when using the --only flag (e.g. if someone ran "firebase serve --only functions:funcA" and they don't actually have a function called funcA). What do you think about an error message like the following?

Error: Cannot understand what targets to deploy. Check that you specified valid targets if you used the --only or --except flag. Otherwise, check your firebase.json to ensure that your project is initialized for the desired features.

@pedrosnk "firebase init" should have populated firebase.json with the correct default options. If it didn't, can you file another bug and include detailed instructions for reproducing?

@laurenzlong That sounds perfect in both cases 👌

First of all thank you for you response :)

I figured out what happened to me. maybe is the same thing that happened to @ahaverty.

I typed $ firebase init and I haven't selected the option hosting by pressing the space.I went to it and pressed the enter key. (haven't read the full message on the the cli).

It was entirely my mistake, but I fell like this mistake could be avoid. Maybe if I press enter into a feature the cli should be able to select it to me automatically. instead of generating an empty firebase.json file.

thanks again for this project.

Context on my use case: I'm wrapping our Firebase deploy commands in bash scripts with some lovely "Are you sure?🤔" checks, as I'm terrified of one day hitting our production project with some crazy Dev code, after not correctly running firebase use devproject! I'm also generating the firebase.json via the script, but was doing some once off rules.bolt merging into my functions repo, and ended up hitting this. @pedrosnk I think your suggestion would break my scripts, but @laurenzlong error message is a good fix👌

Agree better error message in this case is good enough

I agree with @pedrosnk the file should be prepopulated with some default options like:

{
    "hosting": {
        "public": "public",
        "rewrites": [
            {
                "source": "**",
                "destination": "/index.html"
            }
        ],
    }
}

After all everybody is using an SPA with Firebase Hosting.

Just sent a PR to fix the error msg. @pedrosnk and @PierBover what if "firebase init" would not let you progress further if you didn't select any features? We can't really populate hosting by default since some people do not actually use it (for example, if they have a mobile app and are using functions).

Hey @laurenzlong I did select hosting when doing firebase init and I got an empty file.

@PierBover that's a bug then. When I do 'firebase init' and select hosting, I get this in my firbase.json:

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

Could you try to reproduce the bug? And if you can reproduce it, then file another issue? (Please include CLI version, platform you're running.)

Also, you select a feature by pressing space (the circle then becomes filled). If you selected it, then you will be guided through some questions related to hosting (What do you want to use as your public directory? Configure as a single-page app (rewrite all urls to /index.html)?)

You are right, I probably pressed enter instead of space. My bad.

No worries!

Sorry, I'm a newbie and this is the closest discussion to the error I am seeing. On firebase init I chose cloud functions and got an empty firebase.json with curly braces. Now deploying gives me "cannot understand what targets to deploy". Is using hosting a prerequisite to using cloud functions?

Hey @himanshugarg I'm unable to reproduce your bug, you should be able to deploy after just initializing functions. Could you please file a separate issue, and follow the issues template so we can capture more details?

Thank you! @pedrosnk

@laurenzlong thanks for checking. It was my fault. I had moved only some of the firebase files to another directory, causing this. Doing a clean init worked nicely. https://stackoverflow.com/questions/45935600/firebase-cannot-understand-what-targets-to-deploy

In firebase init CLI, one who see brackets ( ) can think it imitate radio button, so chooses an option and hits Enter. I suggest instead square brackets [ ] which suggest multiple-choice (checkboxes).

I also had an empty firebase.json file because of pressing Enter and missed Space.
I haven't read instructions because I had known I need to choose "Hosting" option.

"ignore": [
  "firebase.json",
  "**/.*",
  "**/node_modules/**"
]

// Avoid the etra ',' after the sqr bracket unless u have an arg to go there

I also pressed enter instead of space. I guess it's not a functional issue but is indeed a usability issue

@lelong88 I belive that would happend the first time to many people.

firebase is looking by default in folder 'public' for file 'index.html'.

if in angular4 for example the 'index.html' exists in folder 'dist' you have to go into 'firebase.json' and paste there:

{
"hosting": {
"public": "dist"
}
}

this is direct the firebase to look for 'index.html' in 'dist' folder or whatever is folder call instead 'public'.
of cores you have that your file call 'index.html'.

after that:

firebase deploy

probably will work

worked for me!

Space to select features? Are you stoned?

ahahahah use of a space? LMAO.
Okay, I get why I got an empty file now. ¯_(ツ)_/¯

[debug] [2018-06-03T15:18:34.367Z] ----------------------------------------------------------------------
[debug] [2018-06-03T15:18:34.371Z] Command: C:\Program Files\nodejs\node.exe C:\Users\pushpendraPC\AppData\Roaming\npm\node_modules\firebase-toolsbinfirebase init MyAssignMent
[debug] [2018-06-03T15:18:34.371Z] CLI Version: 3.18.5
[debug] [2018-06-03T15:18:34.371Z] Platform: win32
[debug] [2018-06-03T15:18:34.372Z] Node Version: v10.3.0
[debug] [2018-06-03T15:18:34.373Z] Time: Sun Jun 03 2018 20:48:34 GMT+0530 (India Standard Time)
[debug] [2018-06-03T15:18:34.373Z] ----------------------------------------------------------------------
[debug]
[debug] [2018-06-03T15:18:34.388Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase"]
[debug] [2018-06-03T15:18:34.389Z] > authorizing via signed-in user
[info]
######## #### ######## ######## ######## ### ###### ########
## ## ## ## ## ## ## ## ## ## ##
###### ## ######## ###### ######## ######### ###### ######
## ## ## ## ## ## ## ## ## ## ##
## #### ## ## ######## ######## ## ## ###### ########

You're about to initialize a Firebase project in this directory:

C:\Users\pushpendraPC\Desktop\project\NewAsignMentDeploy\AssignMent\src

Before we get started, keep in mind:

  • You are initializing in an existing Firebase project directory

[info]
=== Project Setup
[info]
[info] First, let's associate this project directory with a Firebase project.
[info] You can create multiple project aliases by running firebase use --add,
[info] but for now we'll just set up a default project.
[info]
[debug] [2018-06-03T15:18:36.584Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects

Sun Jun 03 2018 20:48:36 GMT+0530 (India Standard Time)
[debug] [2018-06-03T15:18:38.115Z] <<< HTTP RESPONSE 200
[info] i .firebaserc already has a default project, skipping
[info]
=== Myassignment Setup
[debug] [2018-06-03T15:18:38.543Z] TypeError: features[nextFeature] is not a function
at init (C:\Users\pushpendraPC\AppData\Roaming\npm\node_modules\firebase-toolslib\init\index.js:13:49)
at C:\Users\pushpendraPC\AppData\Roaming\npm\node_modules\firebase-toolslib\init\index.js:14:14
at process._tickCallback (internal/process/next_tick.js:68:7)
[error]
[error] Error: An unexpected error has occurred.

show error when i run cmd firebase init

Hi,
Below was error in the browser.

Page Not Found
This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.

Why am I seeing this?
You may have deployed the wrong directory for your application. Check your firebase.json and make sure the public directory is pointing to a directory that contains an index.html file.

You can also add a 404.html in the root of your site to replace this page with a custom error page.

*****Command Line ******
firebase deploy

=== Deploying to 'organicshop-18573'...

i deploying hosting
i hosting: preparing dist directory for upload...
⚠ Warning: Public directory does not contain index.html
✔ hosting: 7 files uploaded successfully

✔ Deploy complete!
**** Firebase.Json*******

{
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"/.",
"
/node_modules/"
],
"rewrites": [
{
"source": "
",
"destination": "/index.html"
}
]
}
}
** Folder Structure ****
In dist folder I had index.html. But when i try to deploy it is showing as " The file does not exists and there was no index.html.

type ng build and then type firebase deploy

firebase bad

This original issue seems to be addressed. Since there's been no recent activity, I'm going to close this.

If anyone has additional issues with firebase.json, please open a new issue with the appropriate information!

I have followed the provided solutions but they have not solved my problem.

page does not fetch the data, its blank, but the fav icon is loaded. what cold be the issue

Was this page helpful?
0 / 5 - 0 ratings