Эмулятор Firestore / Firebase не работает - PullRequest
1 голос
/ 16 мая 2019

Я пытаюсь протестировать свои функции локально, используя приведенное здесь руководство. https://firebase.google.com/docs/functions/local-emulator

Я установил новейшие инструменты Firebase, используя

npm install -g firebase-tools

В моем package.json я подтвердил, что запущен

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

Когда я пытаюсь запустить свои функции, используя

firebase emulators:start

Это дает мне следующий вывод. Что я делаю не так?

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\"."} 

Ответы [ 3 ]

6 голосов
/ 21 мая 2019

У меня была та же проблема, но у меня было несколько неправильных вещей

  1. убедитесь, что эмулятор установлен с помощью установки firebase: эмуляторы: 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"
    }
  }
}
2 голосов
/ 15 июня 2019

Если проверка Firebase не работает, попробуйте следующее:

  • Выполнить firebase emulators:start.Проверьте, отображается ли запрос об ошибке для установки OpenJDK.
  • Если ваши функции взаимодействуют с API-интерфейсами Firebase или Google API, вам необходимо установить учетные данные администратора.Проверьте, как это сделать здесь: https://firebase.google.com/docs/functions/local-emulator
  • Возможно, вам придется одновременно эмулировать функции и хранилище.Используйте firebase emulators:start --only functions,firestore или firebase serve --only functions,firestore.
  • Имейте в виду, что pubsub еще не поддерживается.
1 голос
/ 27 мая 2019

Возможно, у вас неправильно настроен firestore в файле firebase.json.Это делает эмулятор не запускаемым.

Вам нужно запустить firebase init firestore в каталоге вашего проекта.Это создаст правила для firestore и файлы индексов и соответственно обновит ваш firebase.json.

...