【问题标题】:Firebase cannot understand what targets to deployFirebase 无法理解要部署的目标
【发布时间】:2018-02-06 16:52:48
【问题描述】:

在部署以下 hello-world 等效代码时,我收到最后显示的错误:-

$ 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 看起来像这样:-

{}

和 index.json 像这样:-

'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);
});

但是部署失败:-

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

【问题讨论】:

    标签: firebase firebase-cli


    【解决方案1】:

    我也遇到了这个问题,因为在我的 Firebase 项目设置开始时,我只初始化了托管功能。后来,当我想使用 Firebase CLI 部署 Firestore 安全规则时,我的初始化过程未完成,此命令无法按预期工作

    我无法运行firebase deploy --only firestore:rules 因为我的firebase.json 文件没有使用默认值初始化。

    解决此问题的最简单和最充分的方法是再次运行 firebase init 命令来设置您要使用的所有功能。您可以手动执行此操作,但您可能会错过命令行界面可以按照默认方式为您设置的详细信息。

    解决办法:

    再次运行firebase init 命令 ...并确保初始化您当前使用的每个功能。请注意不要覆盖重要的配置,如果您已经有一些配置,请仔细阅读 init 命令询问的 Firebase CLI 说明。

    【讨论】:

      【解决方案2】:

      我在跑步时遇到了这个问题:

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

      问题是firebase.json 上必须有你想要的模拟器的属性。所以就我而言,我在firebase.json 上添加了一个"firestore": {} 并工作了。

      【讨论】:

        【解决方案3】:

        我认为您缺少以下内容之一 -

        a) 您应该在 index.html 所在的主项目之外运行 firebase init。 b) 在运行 firebase init 后按 SPACE 选择托管选项 c) 请给出包含 index.html 的文件夹名称。

        您的项目将开始运行。

        【讨论】:

          【解决方案4】:

          面临类似的问题。在 firebase.json 文件中(在主机参数中),我们必须给出我们想要部署的目录的名称(在我的情况下,我已经在我想要部署的目录中,因此我在主机中输入了“.”规格)。它为我解决了错误。

          {
            "hosting": {
              "public": ".",
              "ignore": [
                "firebase.json",
                "**/.*",
                "**/node_modules/**"
              ]
            }
          }
          

          【讨论】:

          • 部署 reactjs 应用,必须将 public 设置为 build/.。够了。
          • "hosting.public" 实际上是web app的根目录。因此,不需要“公共”值。文档需要说明清楚。
          • @FrancisRodrigues 它必须设置为您存储 index.html 的位置(或网站的任何起始页)。 build/. 是您唯一的情况,例如,React 应用程序通常使用 dist 文件夹创建输出文件。
          【解决方案5】:

          Firebase 读取 package.json 以读取 functions 目标的详细信息。我的项目目录中缺少此文件,因为我在执行 init 后移动了文件。

          创建一个干净的目录并在其中执行 firebase 初始化函数,创建了所有开始所需的文件和文件夹。

          【讨论】:

            【解决方案6】:

            最好使用默认选项预先填充 Firebase。我选择我只想使用托管 firebase.json 应该使用默认托管选项创建。

            {
              "hosting": {
                "public": "public"
              }
            }
            

            或者你尝试再次运行firebase init

            【讨论】:

              猜你喜欢
              • 2021-06-24
              • 2019-02-03
              • 1970-01-01
              • 2017-09-01
              • 2020-10-25
              • 2021-10-04
              • 2020-08-02
              • 2018-08-05
              • 2016-09-18
              相关资源
              最近更新 更多