invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.7k stars 2.22k forks source link

Fatal: TypeError undefined is not an object (evaluating 'this._pending[n].meta') #3016

Closed vietmobilefolk closed 4 years ago

vietmobilefolk commented 4 years ago

Issue

Our app get many reports about this issue: Fatal: TypeError undefined is not an object (evaluating 'this._pending[n].meta')

This is our main code block doing with react-native-firebase:

export function saveUserInfo(data) {
  const ref = db.collection("users").doc(auth.currentUser.uid);
  return new Promise((resolve, reject) => {
    db.runTransaction(async transaction => {
      const doc = await transaction.get(ref);
      if (doc.exists) {
        transaction.update(ref, data);
      } else {
        transaction.set(ref, data);
      }
      return doc;
    })
      .then(doc => {
        db.collection("users")
          .doc(auth.currentUser.uid)
          .get()
          .then(
            userInfo => {
              resolve(userInfo.data());
            },
            error => {
              reject(error);
            }
          );
      })
      .catch(error => {
        console.log(error);
        reject(error);
      });
  });
}

Project Files

Javascript

Click To Expand

#### `package.json`: ```json "react-native-firebase": "5.5.6", ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ``` --- ### Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [x] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 21 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "28.0.0" androidMapsUtilsVersion = "0.5+" } repositories { google() mavenLocal() mavenCentral() jcenter() maven { url 'https://maven.fabric.io/public' } maven { url 'https://maven.google.com/' name 'Google' } } dependencies { classpath("com.android.tools.build:gradle:3.4.0") classpath 'com.google.gms:google-services:4.2.0' classpath 'io.fabric.tools:gradle:1.28.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() mavenCentral() mavenLocal() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } maven { url 'https://jitpack.io' } maven { url 'https://maven.google.com/' name 'Google' } maven { url "http://sdk.uxcam.com/android/" } } } ``` #### `android/app/build.gradle`: ```groovy implementation project(':react-native-firebase') implementation project(':react-native-navigation') implementation "com.facebook.react:react-native:+" // From node_modules implementation "com.android.support:appcompat-v7:28.0.0" implementation "com.android.support:design:28.0.0" implementation "com.android.support:support-v4:28.0.0" implementation 'com.facebook.android:facebook-android-sdk:[4,5)' implementation 'com.google.firebase:firebase-core:16.0.9' implementation "com.google.firebase:firebase-auth:17.0.0" implementation "com.google.firebase:firebase-firestore:19.0.0" implementation "com.google.firebase:firebase-storage:17.0.0" implementation 'com.google.android.gms:play-services-location:16.0.0' implementation "com.google.firebase:firebase-invites:17.0.0" implementation "com.google.firebase:firebase-config:17.0.0" ``` #### `android/settings.gradle`: ```groovy include ':react-native-firebase' project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') ``` #### `MainApplication.java`: ```java import io.invertase.firebase.RNFirebasePackage; import io.invertase.firebase.analytics.RNFirebaseAnalyticsPackage; import io.invertase.firebase.auth.RNFirebaseAuthPackage; import io.invertase.firebase.config.RNFirebaseRemoteConfigPackage; import io.invertase.firebase.fabric.crashlytics.RNFirebaseCrashlyticsPackage; import io.invertase.firebase.firestore.RNFirebaseFirestorePackage; import io.invertase.firebase.links.RNFirebaseLinksPackage; import io.invertase.firebase.storage.RNFirebaseStoragePackage; new RNFirebasePackage(), new RNFirebaseAuthPackage(), new RNFirebaseFirestorePackage(), new RNFirebaseStoragePackage(), new RNFirebaseLinksPackage(), new RNFirebaseAnalyticsPackage(), new RNFirebaseCrashlyticsPackage(), new RNFirebaseRemoteConfigPackage() ``` #### `AndroidManifest.xml`: ```xml ```

--- ## Environment
Click To Expand

**`react-native info` output:** ``` React Native Environment Info: System: OS: macOS 10.14.6 CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz Memory: 33.40 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.15.1 - ~/.nvm/versions/node/v8.15.1/bin/node Yarn: 1.17.3 - /usr/local/bin/yarn npm: 6.4.1 - ~/.nvm/versions/node/v8.15.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 Android SDK: API Levels: 19, 20, 22, 23, 24, 25, 27, 28, 29 Build Tools: 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.3, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 27.0.1, 27.0.3, 28.0.0, 28.0.1, 28.0.2, 28.0.3, 29.0.0, 29.0.0, 29.0.2 System Images: android-19 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom IDEs: Android Studio: 3.4 AI-183.6156.11.34.5522156 Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.10 => 0.59.10 npmGlobalPackages: react-native-mobilefolk: 1.0.0``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [x ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `5.5.6` - **`Firebase` module(s) you're using that has the issue:** - `Firestore` - **Are you using `TypeScript`?** - `N`

--- Think `react-native-firebase` is great? Please consider supporting all of the project maintainers and contributors by donating via our [Open Collective](https://opencollective.com/react-native-firebase/donate) where all contributors can submit expenses. [[Learn More]](https://invertase.io/oss/react-native-firebase/contributing/donations-expenses) - 👉 Check out [`React Native Firebase`](https://twitter.com/rnfirebase) and [`Invertase`](https://twitter.com/invertaseio) on Twitter for updates on the library.
mikehardy commented 4 years ago

Looks like some sort of error with regard to transaction handling. Not sure if it is a bug or not, but in this case, a get+update is equivalent to a set isn't it?

To create or overwrite a single document, use the set() method: https://firebase.google.com/docs/firestore/manage-data/add-data - seems inefficient and verbose to structure the code that way, and costs an extra read from firestore

The only time you should use transactions are: Transactions are useful when you want to update a field's value based on its current value, or the value of some other field https://firebase.google.com/docs/firestore/manage-data/transactions#transactions - but maybe I am missing something?

If you got right of the transaction there I bet the error would go away as well. Strangely that string did not appear in source at all, so I'm not sure where it is coming from. A full stack trace might help if restructuring code does not

stale[bot] commented 4 years ago

Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

sehmim commented 4 years ago

I am having a similar issue! was this ever resolved ?