firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

Firebase deploy error message with an empty firebase.json

Open ahaverty opened this issue 9 years ago • 33 comments

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 👍

ahaverty avatar Jun 06 '17 22:06 ahaverty

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"
  }
}

pedrosnk avatar Jun 07 '17 02:06 pedrosnk

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 avatar Jun 09 '17 19:06 laurenzlong

@laurenzlong That sounds perfect in both cases 👌

ahaverty avatar Jun 09 '17 19:06 ahaverty

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.

pedrosnk avatar Jun 09 '17 19:06 pedrosnk

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👌

ahaverty avatar Jun 09 '17 20:06 ahaverty

Agree better error message in this case is good enough

pedrosnk avatar Jun 09 '17 20:06 pedrosnk

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.

PierBover avatar Jun 26 '17 13:06 PierBover

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).

laurenzlong avatar Jun 26 '17 14:06 laurenzlong

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

PierBover avatar Jun 26 '17 14:06 PierBover

@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.)

laurenzlong avatar Jun 26 '17 14:06 laurenzlong

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)?)

laurenzlong avatar Jun 26 '17 14:06 laurenzlong

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

PierBover avatar Jun 26 '17 14:06 PierBover

No worries!

laurenzlong avatar Jun 26 '17 16:06 laurenzlong

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?

himanshugarg avatar Aug 29 '17 11:08 himanshugarg

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?

laurenzlong avatar Aug 29 '17 17:08 laurenzlong

Thank you! @pedrosnk

ghost avatar Sep 07 '17 06:09 ghost

@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

himanshugarg avatar Sep 07 '17 06:09 himanshugarg

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.

volago avatar Sep 26 '17 20:09 volago

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

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

Nditah avatar Oct 06 '17 00:10 Nditah

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

lelong88 avatar Nov 17 '17 00:11 lelong88