Firestore/Firebase 模拟器未运行 [英] Firestore/Firebase Emulator Not Running

查看:20
本文介绍了Firestore/Firebase 模拟器未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此处列出的指南在本地测试我的功能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 模拟器:开始

它给了我以下输出.我做错了什么?

启动模拟器:["functions"]⚠ 您请求的节点"版本8"与您的全球版本11"不匹配✔ 功能:模拟器在 http://localhost:5001 启动i 函数:正在观看 Cloud Functions 的[FUNCTIONS FOLDER PATH]"...⚠ 默认的firebase-admin"实例已创建!⚠ 忽略触发器[FUNCTION NAME]",因为尚不支持服务firebaseauth.googleapis.com".⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.⚠ 忽略触发器[FUNCTION NAME]",因为 Cloud Firestore 模拟器没有运行.等等.等等.等等.i 函数:HTTP 触发器在 http://localhost:5001/[APP NAME]/us-central1/[FUNCTION NAME] 处初始化[2019-05-15T21:43:52.436Z] @firebase/database: FIREBASE 警告:{"code":"app/invalid-credential","message":"提供给的凭据实现initializeApp() 通过 "credential" 属性未能获取有效的 GoogleOAuth2 访问令牌出现以下错误:"获取访问令牌时出错:错误提出请求时:getaddrinfo ENOTFOUND metadata.google.internalmetadata.google.internal:80.错误代码:ENOTFOUND"."}

解决方案

我遇到了同样的问题,我有一些问题

  1. 通过运行确保模拟器已安装firebase setup:emulators:firestore

我的第二个问题是,我的初始 firebase 配置已将配置文件安装到我的主文件夹中,而不是如所述的项目文件夹 [此处] 这意味着我的项目缺少 firestore.rules 和 firestore.indexes.json 以及一些配置设置.

运行 firebase init 来生成这些文件

一旦我解决了这两件事,它就对我有用.我希望这会有所帮助.

作为参考,我的 firebase.json 看起来像这样

<代码>{功能":{预部署":["npm --prefix "$RESOURCE_DIR"运行 lint","npm --prefix "$RESOURCE_DIR"运行构建"]},火库":{规则":firestore.rules",索引":firestore.indexes.json"},托管":{公共":区域",忽略":[firebase.json"、**/.*"、**/node_modules/**"]、重写":[{来源":**",目的地":/index.html";}]},模拟器":{火库":{端口":5002"}}}

I'm trying to test my functions locally using the guide listed here https://firebase.google.com/docs/functions/local-emulator

I have installed the latest firebase-tools using

npm install -g firebase-tools

In my package.json I confirmed to be running

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

When I try to run my functions using

firebase emulators:start

It gives me the below output. What am I doing wrong?

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

解决方案

I had the same issue there were a few things wrong for me

  1. ensure the emulator is installed by running firebase setup:emulators:firestore

My second issue was that my initial firebase configuration had installed the config files into my home folder rather then the project folder as described [here] this meant so my project was missing firestore.rules and firestore.indexes.json and some of the configuration settings.

run firebase init to generate these files

Once I fixed these two things it worked for me. I hope this helps.

As a reference my firebase.json looks like this

{
  "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"
    }
  }
}

这篇关于Firestore/Firebase 模拟器未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆