我正在尝试使用此处列出的指南在本地测试我的功能 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\"."}
答案 0 :(得分:6)
实际上,当用户初始化不带数据库的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 serve --only functions,database
答案 1 :(得分:2)
我遇到了同样的问题,我有些毛病
我的第二个问题是我的初始Firebase配置已将配置文件安装到我的主文件夹中,而不是[here]所述的项目文件夹中,这意味着我的项目缺少firestore.rules和firestore.indexes.json和一些配置设置。
运行firebase初始化以生成这些文件
一旦我修复了这两件事,它便对我有用。我希望这会有所帮助。
作为参考,我的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 :(得分:1)
可能是您在firebase.json文件中没有正确配置Firestore。这将导致模拟器无法启动。
您需要在项目目录中运行firebase init firestore
。这将创建firestore规则和索引文件,并相应地更新您的firebase.json。
答案 3 :(得分:1)
如果检查Firebase设置不起作用,请尝试以下操作:
firebase emulators:start
。检查是否显示安装OpenJDK的错误请求。firebase emulators:start --only functions,firestore
或firebase serve --only functions,firestore
。答案 4 :(得分:0)
从Firebase CLI(7.8.0
版本firebase-tools
开始,有一个新命令firebase init emulators
将帮助您设置所有要运行的仿真器。
答案 5 :(得分:0)
简单修复
firebase-tools
(8.x)firebase.json
{
"functions": {
...
},
"firestore": {}
}
这将告诉firebase-tools
初始化并运行Firestore模拟器。
答案 6 :(得分:0)
对我来说,在安装完 java 运行时后,一切都运行良好。
答案 7 :(得分:0)
也遇到了这个问题,我正在导入数据,但是我在错误的目录中,简单修复。希望这可以帮助某人,因为错误输出没有任何指示。
原始命令:
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
答案 8 :(得分:0)
在 firebase.json 文件中将 Firestore 的主机更改为
"host": "http://localhost"
(在 firebase init 命令期间创建)
"host": "localhost"
详细说明: 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://”部分。