2017-08-29 131 views
3

當部署以下你好世界等效代碼我得到最終顯示的錯誤: -火力地堡無法理解部署什麼目標

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

回答

7

預先使用默認選項填充Firebase會更好。我選擇僅使用託管firebase.json的應用程序應使用默認託管選項創建。

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

或您嘗試再次運行firebase init

+0

做一個firebase初始化工作。謝謝。 – Himanshu

1

Firebase讀取package.json以讀取函數目標的詳細信息。這個文件從我的項目目錄中丟失,因爲我在執行init之後移動了文件。

創建一個乾淨的目錄並做一個firebase初始化函數裏面創建了所有需要的文件和文件夾來開始。

3

面對類似問題。在firebase.json文件中(在託管參數中),我們必須給出我們想要部署的目錄名稱(在我的情況下,我已經在我想部署的目錄中,因此我將「。」放在託管規範)。它解決了我的錯誤。

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

對於部署reactjs應用程序,必須將'public'設置爲'build/.'。這就夠了。 –

1

我認爲你缺少對下面的事情一個 -

a)您應該運行的主要項目中的index.html是火力初始化之外。 b)通過按SPACE 運行Firebase初始化後選擇託管選項c)請給出包含index.html的文件夾名稱。

並且您的項目將運行。