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

Firebase deploy error message with an empty firebase.json #367

Closed
ahaverty opened this issue Jun 6, 2017 · 33 comments
Closed

Firebase deploy error message with an empty firebase.json #367

ahaverty opened this issue Jun 6, 2017 · 33 comments
Assignees

Comments

@ahaverty
Copy link

ahaverty commented Jun 6, 2017

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 👍

@pedrosnk
Copy link

pedrosnk commented Jun 7, 2017

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

@laurenzlong
Copy link
Contributor

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?

@ahaverty
Copy link
Author

ahaverty commented Jun 9, 2017

@laurenzlong That sounds perfect in both cases 👌

@pedrosnk
Copy link

pedrosnk commented Jun 9, 2017

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.

@ahaverty
Copy link
Author

ahaverty commented Jun 9, 2017

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👌

@pedrosnk
Copy link

pedrosnk commented Jun 9, 2017

Agree better error message in this case is good enough

@PierBover
Copy link

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.

@laurenzlong
Copy link
Contributor

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

@PierBover
Copy link

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

@laurenzlong
Copy link
Contributor

@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
Copy link
Contributor

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

@PierBover
Copy link

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

@laurenzlong
Copy link
Contributor

No worries!

@himanshugarg
Copy link

himanshugarg commented Aug 29, 2017

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?

@laurenzlong
Copy link
Contributor

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?

@tranphuoctien
Copy link

Thank you! @pedrosnk

@himanshugarg
Copy link

@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

@volago
Copy link

volago commented Sep 26, 2017

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.

@laurenzlong laurenzlong self-assigned this Sep 29, 2017
@laurenzlong laurenzlong reopened this Sep 29, 2017
@Nditah
Copy link

Nditah commented Oct 6, 2017

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

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

@lelong88
Copy link

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

@burzumumbra
Copy link

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

@israellev
Copy link

israellev commented Dec 7, 2017

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

@dragGH102
Copy link

worked for me!

@gazedash
Copy link

Space to select features? Are you stoned?

@Vadorequest
Copy link

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

@pushpendra2636
Copy link

[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-tools\bin\firebase 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-tools\lib\init\index.js:13:49)
at C:\Users\pushpendraPC\AppData\Roaming\npm\node_modules\firebase-tools\lib\init\index.js:14:14
at process._tickCallback (internal/process/next_tick.js:68:7)
[error]
[error] Error: An unexpected error has occurred.

@pushpendra2636
Copy link

show error when i run cmd firebase init

@Venkat517
Copy link

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.

@manikyak
Copy link

type ng build and then type firebase deploy

@ahmedfaisall
Copy link

firebase bad

@bkendall
Copy link
Contributor

bkendall commented Jan 9, 2019

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!

@bkendall bkendall closed this as completed Jan 9, 2019
@wilbrone
Copy link

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

@dhayaljaswantgit
Copy link

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.

This is the right solution

@firebase firebase locked as resolved and limited conversation to collaborators Jul 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests