Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase cannot understand what targets to deploy

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.
like image 896
Himanshu Avatar asked Aug 29 '17 09:08

Himanshu


People also ask

Should firebase JSON be committed?

firebaserc is environment/machine specific, and thus should not be committed to the repository.

How do I change the default project in firebase?

1 Answer. Show activity on this post. Then in the list of projects, select your project. And then finally for the alias name enter default (or whatever you entered before).


4 Answers

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.

like image 116
Natan Deitch Avatar answered Oct 13 '22 20:10

Natan Deitch


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.

like image 28
aofdev Avatar answered Oct 13 '22 20:10

aofdev


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/**"
    ]
  }
}
like image 9
Raxit Solanki Avatar answered Oct 13 '22 18:10

Raxit Solanki


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.

like image 2
Alexandre Desroches Avatar answered Oct 13 '22 19:10

Alexandre Desroches