Search code examples
javascriptfirebasegoogle-cloud-firestorenuxt.jsnuxtjs3

Firestore Document creation leads to GrpcConnection Error Nuxt3


I want to use the Firebase/Firestore SDK for my Nuxt3 application. When i want to store a new doc in my firestore db it allways leads to the following Error:

@firebase/firestore: Firestore (10.11.0): GrpcConnection RPC 'Write' stream 0x29b0fa74 error. Code: 5 Message: 5 NOT_FOUND:

This is how i store the data:

export const add = async (col: string, document: Object) => {
  // @ts-ignore
  const colRef = collection(firestoreDb, col);

  const docRef = await addDoc(colRef, document);

  return docRef;
};

The fully code can be found here: https://github.com/julix14/attraction_stack/commit/a5a9c1110f57ad9c80ea425368efde4411a69c83

Is anybody knowing what this error means, what it causes and how to fix it?

EDIT: I added loggings to see the firestoreDb instance and the colRef:

    Firestore {
  _authCredentials:
   FirebaseAuthCredentialsProvider {
     authProvider:
      Provider {
        name: 'auth-internal',
        container: [ComponentContainer],
        component: null,
        instances: Map(0) {},
        instancesDeferred: Map(0) {},
        instancesOptions: Map(0) {},
        onInitCallbacks: Map(0) {} },
     currentUser: User { uid: null },
     tokenCounter: 0,
     forceRefresh: false,
     auth: null },
  _appCheckCredentials:
   FirebaseAppCheckTokenProvider {
     appCheckProvider:
      Provider {
        name: 'app-check-internal',
        container: [ComponentContainer],
        component: null,
        instances: Map(0) {},
        instancesDeferred: Map(0) {},
        instancesOptions: Map(0) {},
        onInitCallbacks: Map(0) {} },
     forceRefresh: false,
     appCheck: null,
     latestAppCheckToken: null },
  _databaseId: DatabaseId { projectId: 'activityapp-419511', database: '(default)' },
  _app:
   FirebaseAppImpl {
     _isDeleted: false,
     _options:
      { apiKey: 'AIzaSyAQVJufWha_adYk879BEpM4BwUl4XggkEc',
        authDomain: 'activityapp-419511.firebaseapp.com',
        databaseURL: undefined,
        projectId: 'activityapp-419511',
        storageBucket: 'activityapp-419511.appspot.com',
        messagingSenderId: '412317674095',
        appId: '1:412317674095:web:6792a01c7499d1ce44fb9a' },
     _config: { name: 'server', automaticDataCollectionEnabled: false },
     _name: 'server',
     _automaticDataCollectionEnabled: false,
     _container: ComponentContainer { name: 'server', providers: [Map] } },
  type: 'firestore',
  _persistenceKey: 'server',
  _settings:
   FirestoreSettingsImpl {
     host: 'firestore.googleapis.com',
     ssl: true,
     credentials: undefined,
     ignoreUndefinedProperties: false,
     localCache: undefined,
     cacheSizeBytes: 41943040,
     experimentalForceLongPolling: false,
     experimentalAutoDetectLongPolling: true,
     experimentalLongPollingOptions: {},
     useFetchStreams: true },
  _settingsFrozen: false,
  _queue:
   <ref *1> AsyncQueueImpl {
     tail: Promise { undefined },
     retryableOps: [],
     _isShuttingDown: false,
     delayedOperations: [],
     failure: null,
     operationInProgress: false,
     skipNonRestrictedTasks: false,
     timerIdsToSkip: [],
     backoff:
      ExponentialBackoff {
        queue: [Circular *1],
        timerId: 'async_queue_retry',
        initialDelayMs: 1000,
        backoffFactor: 1.5,
        maxDelayMs: 60000,
        currentBaseMs: 0,
        timerPromise: null,
        lastAttemptTime: 1714043517590 },
     visibilityHandler: [Function (anonymous)] } }

ColRef:

CollectionReference {
  converter: null,
  _query:
   QueryImpl {
     path: ResourcePath { segments: [Array], offset: 0, len: 1 },
     collectionGroup: null,
     explicitOrderBy: [],
     filters: [],
     limit: null,
     limitType: 'F',
     startAt: null,
     endAt: null,
     memoizedNormalizedOrderBy: null,
     memoizedTarget: null,
     memoizedAggregateTarget: null },
  type: 'collection',
  firestore:
   Firestore {
     _authCredentials:
      FirebaseAuthCredentialsProvider {
        authProvider: [Provider],
        currentUser: [User],
        tokenCounter: 0,
        forceRefresh: false,
        auth: null },
     _appCheckCredentials:
      FirebaseAppCheckTokenProvider {
        appCheckProvider: [Provider],
        forceRefresh: false,
        appCheck: null,
        latestAppCheckToken: null },
     _databaseId: DatabaseId { projectId: 'activityapp-419511', database: '(default)' },
     _app:
      FirebaseAppImpl {
        _isDeleted: false,
        _options: [Object],
        _config: [Object],
        _name: 'server',
        _automaticDataCollectionEnabled: false,
        _container: [ComponentContainer] },
     type: 'firestore',
     _persistenceKey: 'server',
     _settings:
      FirestoreSettingsImpl {
        host: 'firestore.googleapis.com',
        ssl: true,
        credentials: undefined,
        ignoreUndefinedProperties: false,
        localCache: undefined,
        cacheSizeBytes: 41943040,
        experimentalForceLongPolling: false,
        experimentalAutoDetectLongPolling: true,
        experimentalLongPollingOptions: {},
        useFetchStreams: true },
     _settingsFrozen: false,
     _queue:
      AsyncQueueImpl {
        tail: [Promise],
        retryableOps: [],
        _isShuttingDown: false,
        delayedOperations: [],
        failure: null,
        operationInProgress: false,
        skipNonRestrictedTasks: false,
        timerIdsToSkip: [],
        backoff: [ExponentialBackoff],
        visibilityHandler: [Function (anonymous)] } },
  _path: ResourcePath { segments: [ 'activities' ], offset: 0, len: 1 } }

Solution

  • So actually the Code was working, but there was an issue with the datastore in the google cloud wich caused the error. setLogLevel("debug") was the missing puzzle piece to resolve this.