繁体   English   中英

无法访问 Cloud Firestore 后端。 连接失败1次

[英]Could not reach Cloud Firestore backend. Connection failed 1 times

我正在使用一个非常简单的代码并从 firestore 获取数据

import firebase from 'firebase/app';
import 'firebase/firestore'

const firebaseApp = firebase.initializeApp({
        apiKey: "...",
        authDomain: "...",
        ....
    });
    
const db = firebaseApp.firestore();
    
export default db;

但我一直收到这个错误

[2021-06-05T00:58:41.274Z]  @firebase/firestore: Firestore (8.6.5): Could not reach Cloud Firestore backend. Connection failed 1 times.
Most recent error: FirebaseError: [code=permission-denied]:
 Permission denied on resource project.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

  1. 我的互联网连接速度非常快
  2. 我的时钟也与标准时间同步

现在,我不知道为什么会这样?

请有人帮帮我!!!

我面临着同样的问题。 该连接在某些环境中有效,但在我客户的公司网络上却不是。

在互联网上进行了长时间的研究后,我在 Github 上发现了一个关于它的问题

这对我有用:

const firestoreDB = initializeFirestore(firebaseApp, {
  experimentalForceLongPolling: true, // this line
  useFetchStreams: false, // and this line
})

这里我使用的是 firebase v9。 对于 firebase v8,它类似于:

firebase().firestore().settings({
  experimentalForceLongPolling: true, // this line
  useFetchStreams: false, // and this line
})

我能够通过直接使用我的凭证来解决这个问题,我在初始化应用程序我的 firebase 配置,我以前从我的 env 文件中调用它们我认为我的应用程序之前没有获得 env

我遇到了同样的问题并尝试使用@atunde arisekola 方法。 如果您可以通过在firebaseConfig变量中使用直接凭据来解决此问题,请考虑检查您正在使用的.env.local或任何其他.env是否位于根目录中。 在我的例子中,在同一目录中有firebaseConfig.ts.env.local ,因此发生了错误。 建议将.env放在您的 App 的根目录中。

angular fire 我也遇到过这个问题。 我所做的更改是将firestore设置添加到应用程序模块的提供者:

根据GitHub问题讨论,我想你可以先试试experimentalAutoDetectLongPolling 并且选项useFetchStreams是不必要的,除非用户使用非常旧的浏览器版本。

import { SETTINGS as FIRESTORE_SETTINGS } from '@angular/fire/firestore';


providers:[
    {
      provide: FIRESTORE_SETTINGS,
      useValue: { experimentalAutoDetectLongPolling: true, merge: true },
    }
]

并且您可以使用mitmproxy重现 firebase 错误。

确保您的环境指向真正的 Firestone 数据库,而不是 Firestore 模拟器。 当我遇到同样的问题时,这就是原因。

我正在使用 Angular 框架,所以我不得不在我的 app.module.ts 文件中注释掉那些环境引用。

@NgModule({
  declarations: [AppComponent, InformUserComponent],
  entryComponents: [InformUserComponent],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AppRoutingModule,
    ServiceWorkerModule.register('ngsw-worker.js', {
      enabled: environment.production,
      // Register the ServiceWorker as soon as the app is stable
      // or after 30 seconds (whichever comes first).
      registrationStrategy: 'registerWhenStable:30000'
    }),

  ],
  providers: [AuthService, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    // {
    //   provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ?
    //     ['localhost', 8080] : undefined
    // },
    // {
    //   provide: USE_FUNCTIONS_EMULATOR, useValue: environment.useEmulators ?
    //     ['localhost', 5001] : undefined
    // },
  ],
  bootstrap: [AppComponent],
})
export class AppModule { }

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM