【发布时间】:2021-03-11 23:38:39
【问题描述】:
首先,这是我得到的完整错误。
@firebase/firestore:Firestore (8.1.1):主机已在 settings() 和 useEmulator() 中设置,将使用模拟器主机
错误 [FirebaseError]:Firestore 已启动,无法再更改其设置。您只能在调用 Firestore 对象上的任何其他方法之前修改设置。
这就是我启动模拟器的方式
const db = app.firestore();
const auth = firebase.auth();
if (process.env.NODE_ENV === 'development') {
db.useEmulator('localhost', 8888);
firebase.auth().useEmulator('http://localhost:9099/');
}
当我第一次启动应用程序时,项目正在运行 nextjs,一切都按预期运行,但是在 next.js 页面之间进行一些刷新或导航后,我突然收到此错误。我必须杀死终端并重新开始,这很烦人我不知道 next.js 服务器是否多次运行 if (process.env.NODE_ENV === 'development') 代码,如果是这种情况,这可能是导致此错误的原因如何避免设置新的模拟器,当已经有一个时。还是与 firebase 模拟器相关的错误?
【问题讨论】:
-
您是否从数据库设置中启用 Persistence 参数?我找到了this GitHub issue,其中提到了 Persistence,但出现了类似的错误。
-
@ArtemisGeorgakopoulou 不,我实际上没有添加任何自定义设置,我只使用
useEmulator方法,但在此之前,我将开发中的本地主机添加为js firestore().settings({ host: 'http://localhost:8080', ssl: false })但我有这个错误``` 错误 [FirebaseError]:Firestore 已启动,无法再更改其设置。您只能在调用 Firestore 对象上的任何其他方法之前修改设置。 ``` 当我使用 useEmulator 时,它经常发生,但很少发生。 -
1500 以上的人可以建议在 StackOverflow 上使用 Firebase-emulators 标签吗?
-
在“db.useEmulator('localhost', 8888);”行中,你有没有尝试过设置8080端口而不是设置中的配置?
-
Postgres 使用 8080,所以我将 8888 配置为 firestore 的端口
标签: reactjs firebase google-cloud-firestore next.js firebase-cli