簡體   English   中英

Firestore/Firebase 模擬器未運行

[英]Firestore/Firebase Emulator Not Running

我正在嘗試使用此處列出的指南https://firebase.google.com/docs/functions/local-emulator在本地測試我的功能

我已經安裝了最新的 firebase-tools 使用

npm install -g firebase-tools

在我的package.json我確認正在運行

"firebase-admin": "^7.3.0", "firebase-functions": "^2.3.1",

當我嘗試使用

firebase emulators:start

它給了我下面的 output。 我究竟做錯了什么?

Starting emulators: ["functions"]
⚠  Your requested "node" version "8" doesn't match your global version "11"
✔  functions: Emulator started at http://localhost:5001
i  functions: Watching "[FUNCTIONS FOLDER PATH]" for Cloud Functions...
⚠  Default "firebase-admin" instance created!
⚠  Ignoring trigger "[FUNCTION NAME]" because the service "firebaseauth.googleapis.com" is not yet supported.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.
⚠  Ignoring trigger "[FUNCTION NAME]" because the Cloud Firestore emulator is not running.

etc.
etc.
etc.
i  functions: HTTP trigger initialized at http://localhost:5001/[APP NAME]/us-central1/[FUNCTION NAME]

[2019-05-15T21:43:52.436Z]  @firebase/database: FIREBASE WARNING:  
{"code":"app/invalid-credential","message":"Credential implementation provided to   
initializeApp() via the \"credential\" property failed to fetch a valid Google  
OAuth2 access token with the following error: \"Error fetching access token: Error  
while making request: getaddrinfo ENOTFOUND metadata.google.internal  
metadata.google.internal:80. Error code: ENOTFOUND\"."} 

我遇到了同樣的問題,我有一些問題

  1. 通過運行firebase setup:emulators:firestore確保安裝了firebase setup:emulators:firestore

我的第二個問題是,我的初始 firebase 配置已將配置文件安裝到我的主文件夾中,而不是[此處]所述的項目文件夾中,這意味着我的項目缺少 firestore.rules 和 firestore.indexes.json 以及一些配置設置.

運行 firebase init 來生成這些文件

一旦我解決了這兩件事,它就對我有用。 我希望這有幫助。

作為參考,我的 firebase.json 看起來像這樣

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "hosting": {
    "public": "dist",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "emulators": {
    "firestore": {
      "port": "5002"
    }
  }
}

如果檢查 Firebase 設置不起作用,請嘗試以下操作:

  • 運行firebase emulators:start 檢查是否顯示安裝 OpenJDK 的錯誤請求。
  • 如果您的函數與 Firebase API 或 Google API 交互,則需要設置管理員憑據。 在此處檢查如何操作: https : //firebase.google.com/docs/functions/local-emulator
  • 您可能需要同時模擬函數和 firestore。 使用firebase emulators:start --only functions,firestorefirebase serve --only functions,firestore
  • 請記住,尚未支持 pubsub。 正如 Sam Stern 評論的那樣,現在支持 pub sub。

可能是您的 firebase.json 文件中沒有正確配置 firestore。 這使得模擬器無法啟動。

你需要的是在你的項目目錄中運行firebase init firestore 這將創建 firestore 規則和索引文件,並相應地更新您的 firebase.json。

從 Firebase CLI ( firebase-tools ) 7.8.0版本開始,有一個新命令firebase init emulators可以幫助您設置要運行的所有模擬器。

實際上,當用戶在沒有數據庫的情況下初始化 firebase 項目時,就會出現此錯誤。 所以命令firebase emulators:start --only database無法啟動數據庫模擬器,因為它需要“database.rules.json”文件和 firebase.json 文件中的數據庫配置條目。 因此,如果您忘記在firebase init命令中初始化數據庫,那么您可以隨時按照 firebase CLI 命令添加 firebase 數據庫

firebase init database

然后您可以運行firebase emulators:start --only database以在firebase emulators:start --only database中啟動數據庫模擬器。

並且如果您想對函數和數據庫使用模擬器,請運行firebase serve --only functions,database

簡單的修復

  1. 檢查您是否擁有最新的firebase-tools (8.x)
  2. firebase.json添加一個空的Firestore配置
{
  "functions": {
    ...
  },
  "firestore": {}
}

這將告訴firebase-tools初始化並運行 firestore 模擬器。

在此處輸入圖片說明

對我來說,在安裝了 java 運行時之后,一切都運行良好。

安裝 Java 運行時

也遇到了這個問題,我正在導入數據,但是我在錯誤的目錄中,簡單修復。 希望這可以幫助某人,因為錯誤輸出沒有給出任何指示。

原始命令:

firebase emulators:start --import ./firebaseexport

錯誤:

i  emulators: Starting emulators: functions, firestore, hosting
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub

Error: An unexpected error has occurred.

使固定:

firebase emulators:start --import ./functions/firebaseexport

在 firebase.json 文件中,將 Firestore 的主機更改為

"host": "http://localhost"

(在 firebase init 命令期間創建)到

"host": "localhost"

這樣做可以解決問題,並且 firestore 模擬器會運行。

詳細說明:firebase 版本 9.16.0

使用 firebase.json 片段

{
        // ...
        "emulators": {
          "firestore": {
            "host": "http://localhost",
            "port": "8081"
          }
        }
      }

模擬器將停止:

firebase emulators:start --only firestore
i  emulators: Starting emulators: firestore
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
⚠  firestore: Port 8081 is not open on http://localhost, could not start Firestore Emulator.
⚠  firestore: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "firestore": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

Error: Could not start Firestore Emulator, port taken.

但是當“http:localhost”更改為“localhost”時,它就可以工作了(錯誤消息是誤導性的)。

關鍵是(在調試模式下)這條線

port check error: Error: getaddrinfo ENOTFOUND http://localhost

另一個鏈接中的一個建議是檢查 /etc/hosts,但更簡單的解決方法是去掉“http://”部分。

我通過這樣做來修復它

  1. firebase 初始化

select 使用空格鍵需要的東西 然后完成后

  1. firebase 仿真器:開始

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM