sie*_*fix 8 firebase firebase-tools google-cloud-functions google-cloud-firestore firebase-cli
我正在尝试使用此处列出的指南在本地测试我的功能 :https://firebase.google.com/docs/functions/local-emulator
我已经安装了最新的firebase-tools
npm install -g firebase-tools
在我package.json我确认正在运行
Run Code Online (Sandbox Code Playgroud)"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\"."}
Run Code Online (Sandbox Code Playgroud)
小智 13
我遇到了同样的问题,我有些问题
我的第二个问题是我的初始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"
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 12
可能是您的 firebase.json 文件中没有正确配置 firestore。这使得模拟器无法启动。
您需要的是firebase init firestore在您的项目目录中运行。这将创建 firestore 规则和索引文件,并相应地更新您的 firebase.json。
Sam*_*ern 11
从7.8.0Firebase CLI ( firebase-tools)版本开始,有一个新命令firebase init emulators可以帮助您设置要运行的所有模拟器。
小智 8
如果检查Firebase设置不起作用,请尝试以下操作:
firebase emulators:start。检查是否显示错误请求以安装OpenJDK。firebase emulators:start --only functions,firestore或firebase serve --only functions,firestore。实际上,当用户在没有数据库的情况下初始化 firebase 项目时,就会出现此错误。因此该命令firebase emulators:start --only database无法启动数据库模拟器,因为它需要“database.rules.json”文件和 firebase.json 文件中的数据库配置条目。因此,如果您忘记在firebase init命令中初始化数据库,那么您可以随时按照 firebase CLI 命令添加 firebase 数据库
firebase init database
然后您可以firebase emulators:start --only database
在 localserver 中运行
以启动数据库模拟器。
如果您想对函数和数据库都使用模拟器,则运行
firebase serve --only functions,database
简单修复
firebase-tools(8.x)firebase.json{
"functions": {
...
},
"firestore": {}
}
Run Code Online (Sandbox Code Playgroud)
这将告诉firebase-tools您初始化并运行 firestore 模拟器。
| 归档时间: |
|
| 查看次数: |
5677 次 |
| 最近记录: |