Firebase cannot understand what targets to deploy
Asked Answered
A

7

16

When deploying the following hello-world equivalent code I get the error shown in the end:-

$ ls -lR
.:
total 8
-rw-r--r-- 1 hgarg hgarg    3 Aug 29 14:55 firebase.json
drwxr-xr-x 2 hgarg hgarg 4096 Aug 29 11:56 functions

./functions:
total 4
-rw-r--r-- 1 hgarg hgarg 1678 Aug 29 11:56 index.js

firebase.json looks like this:-

{}

and index.json like this:-

'use strict';

const functions = require('firebase-functions');

exports.search = functions.https.onRequest((req, res) => {
  if (req.method === 'PUT') {
    res.status(403).send('Forbidden!');
  }

  var category = 'Category';
  console.log('Sending category', category);
  res.status(200).send(category);
});

But deploying fails:-

$ firebase deploy

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.

$ firebase deploy --only functions

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.
Aprilaprile answered 29/8, 2017 at 9:36 Comment(0)
D
21

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

or you try run firebase init again.

Dallis answered 29/8, 2017 at 9:51 Comment(0)
L
9

Faced similar issue. In firebase.json file (in hosting parameter), we have to give the name of directory that we want to deploy (in my case, I was already in the directory, which I wanted to deploy, hence I put "." in hosting specification). It solved the error for me.

{
  "hosting": {
    "public": ".",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}
Laterite answered 10/12, 2017 at 11:39 Comment(3)
For deploy reactjs app, it must be set public to build/.. That's enough.Ambulance
"hosting.public" is actually the root directory of web app. So "public" value is not required. Documentation needs to make it clear.Absquatulate
@FrancisRodrigues It must be set to where you store index.html (or any start page of the website). build/. is your only case, React app often created with dist folder for output files for example.Absquatulate
B
5

I was facing this issue when running:

firebase emulators:exec --only firestore 'npm tst'

The problem was that on firebase.json must have a property for the emulator you want. So in my case I added a "firestore": {} on firebase.json and worked.

Bering answered 5/12, 2019 at 21:3 Comment(0)
U
4

I faced this problem too because at the beginning of my Firebase project setup, I only initialized the hosting feature. Later on, when I wanted to deploy firestore security rules with the Firebase CLI, my initialization process was not complete for this command to work as expected.

I could not run firebase deploy --only firestore:rules because my firebase.json file was not initialized with defaults.

Easiest and most adequate way to fix this problem is to run the firebase init command again to setup all features you want to use. You could do it manually but you could miss details that the command line interface can setup for you in the exact way it needs to be for defaults.

Solution:

Run the firebase init command again ...and make sure to initialize every feature you are currently using. Take care not to overwrite important configs if you already have some by carefully reading the Firebase CLI instructions that are asked by the init command.

Upsilon answered 8/10, 2021 at 12:52 Comment(1)
currently, if you run firebase init the wizard will create: "database": { "rules": "database.rules.json" } in the firesabe.json, so the right command to deploy the rules is firebase deploy --only database: rulesBorrowing
A
1

Firebase reads package.json to read details of the functions target. This file was missing from my project directory, as I had moved files around after doing an init.

Creating a clean directory and doing a firebase init functions inside it created all the required files and folders to get started.

Aprilaprile answered 29/8, 2017 at 13:51 Comment(0)
S
1

I think you are missing on one of the following things -

a) you should run firebase init outside of the main project where index.html is. b) select hosting option after running firebase init by pressing SPACE c) Please give folder name which contain index.html in it.

And your project will be up running.

Sinuous answered 7/1, 2018 at 9:21 Comment(0)
S
0

For me this worked,

firebase logout

firebase login

Stereo answered 20/5, 2024 at 12:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.