firebase - 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 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\"."}
解决方案
我遇到了同样的问题,对我来说有一些问题
- 确保通过运行安装模拟器
firebase setup:emulators:firestore
我的第二个问题是我的初始 firebase 配置已将配置文件安装到我的主文件夹而不是[here]描述的项目文件夹中, 这意味着我的项目缺少 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"
}
}
}
推荐阅读
- c# - 错误 CS1022:类型或命名空间定义,或文件结尾预期统一 3d 游戏引擎
- python - Azure 机器学习在训练样本上失败
- algorithm - 递归计算数据的运行平均值
- node.js - 无法读取未定义的属性“代码”,解码 Firebase ID 令牌失败
- python - 使用 Pandas 访问单个单元格
- google-app-engine - 我可以在 Google App Engine 上使用通配符域吗?
- mysql - 不为 NULL 时对查询结果进行分组
- java - addListenerOnButton 在 Android Studio 的片段中不起作用
- c# - 由于枚举使用动态时如何访问 Dapper 结果
- node.js - nodejs中的环境变量在控制台内工作,记录但将参数传递给函数时出错