Firebase cannot understand what targets to deploy

寵の児 提交于 2020-02-01 16:39:05

问题


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.

回答1:


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.




回答2:


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/**"
    ]
  }
}



回答3:


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.




回答4:


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.




回答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.



来源:https://stackoverflow.com/questions/45935600/firebase-cannot-understand-what-targets-to-deploy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!