【发布时间】:2020-12-18 14:58:05
【问题描述】:
Firebase 模拟器对本地 FireStore 的请求不成功
你好,
我正在尝试设置 Firebase 模拟器,但我的应用仍在连接到 Firebase(web)。当我执行 db.collection("users").add() 时,我看到 https://console.firebase.google.com 上的条目不在 http://localhost:4000/firestore 上(主机端口是 8080,查看器端口是 4000)
这是我到目前为止所做的:
-
Firebase 模拟器:开始返回“所有模拟器都准备好了!”
-
Firebase.json 看起来不错(端口看起来不错)
"emulators": {
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"database": {
"port": 9000
},
"hosting": {
"port": 5000
},
"pubsub": {
"port": 8085
},
"ui": {
"enabled": true
}
- 在初始化应用程序之前,我将 databaseURL 更改为我的本地 firestore。 请注意,在视频“The Local Firebase Emulator UI in 15 minutes”(https://www.youtube.com/watch?v=pkgvFNPdiEs 5:19)中,David East 将整个配置对象替换为“config = { databaseURL: '...' }”,但它返回此错误: “未捕获的 FirebaseError:firebase.initializeApp 中未提供“projectId”,如果我添加 value-key projectId,它会返回丢失的其他错误。
if (location.hostname === "localhost") {
config.databaseURL = "http://localhost:8080?ns=project_name";
}
firebase.initializeApp(config);
- Firebase 使用好项目 (Firebase Firestore works with real database but not emulator)
firebase use project_name
- 我还创建了 Google Cloud Platform 私钥...以防万一。
我认为我的问题可能出在第 3 步,但我找不到解决方法。你有什么想法吗?你会怎么做才能让它发挥作用?
谢谢!
【问题讨论】:
-
@DougStevenson 感谢您纠正拼写错误。
-
我在观看同一个视频后遇到了完全相同的问题。
标签: javascript firebase firebase-cli