web-dev-qa-db-ja.com

Firebaseはデプロイするターゲットを理解できません

次の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.
11
Himanshu

firebaseにデフォルトのオプションを事前に入力することをお勧めします。私は、firebase.jsonのホスティングのみを使用することを選択し、デフォルトのホスティングオプションで作成する必要があります。

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

またはあなたはfirebase init再び。

12
aofdev

同様の問題に直面しました。 (hostingパラメータの)firebase.jsonファイルで、デプロイするディレクトリの名前を指定する必要があります(私の場合、私はデプロイしたいディレクトリにすでにいたので、ホスティングに「。」を入れます仕様)。それは私のためにエラーを解決しました。

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

次のいずれかが不足していると思います-

a)index.htmlがあるメインプロジェクトの外でfirebase initを実行する必要があります。 b)[〜#〜] space [〜#〜]を押して、firebase initを実行した後、ホスティングオプションを選択しますc)index.htmlを含むフォルダー名を指定してください。

そして、あなたのプロジェクトは稼働し始めます。

1
avinash singh

Firebaseはpackage.jsonを読み取り、functionsターゲットの詳細を読み取ります。 initを実行した後でファイルを移動したため、このファイルはプロジェクトディレクトリにありませんでした。

クリーンなディレクトリを作成してfirebase init functionsを実行すると、開始に必要なすべてのファイルとフォルダーが作成されます。

1
Himanshu