React-native-firebase: Crash: TypeError Object.defineProperty() argument is not an object

Created on 3 May 2020  路  10Comments  路  Source: invertase/react-native-firebase


Issue



Crashing on messaging module.
Stacktrace has given here

TypeError Object.defineProperty() argument is not an object 
    native defineProperty
    node_modules/@react-native-firebase/messaging/lib/index.js:204:13 anonymous
    native apply
    node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:189:32 value

Project Files







Javascript

Messaging/index.js:

Click To Expand

onTokenRefresh(listener) {
    if (!isFunction(listener)) {
      throw new Error("firebase.messaging().onTokenRefresh(*) 'listener' expected a function.");
    }
    const subscription = this.emitter.addListener('messaging_token_refresh', event => {
      // TODO remove after v7.0.0, see: https://github.com/invertase/react-native-firebase/issues/2889
      const { token } = event;
      const tokenStringWithTokenAccessor = String(token);
      Object.defineProperty(tokenStringWithTokenAccessor, 'token', {
        enumerable: false,
        get() {
          // eslint-disable-next-line no-console
          console.warn(
            'firebase.messaging().onTokenRefresh(event => event.token) is deprecated, use onTokenRefresh(token => token) or call getToken() instead',
          );
          return token;
        },
      });
      listener(tokenStringWithTokenAccessor);
    });
    return () => subscription.remove();
  }

**Usage:**

const unsubscribe = messaging().onTokenRefresh(token => {
      typeof onTokenRefresh === "function" && onTokenRefresh(token);
  });
#### `package.json`: "@react-native-firebase/messaging": "6.7.1", #### `firebase.json` for react-native-firebase v6: `{ "react-native": { "messaging_android_notification_channel_id": "curefit_notification_id", "messaging_ios_auto_register_for_remote_messages": false } }`
# N/A
### Android
Click To Expand

#### Have you converted to AndroidX? - [x] my application is an AndroidX application? - [x] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [x] I am using the NPM package `jetifier` for react-native compatibility? ## Environment

Click To Expand

**`react-native info` output:**

System:
    OS: macOS 10.15.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 3.44 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.3 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 25, 26, 27, 28, 29
      Build Tools: 28.0.0, 28.0.3, 29.0.2
      System Images: android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: ^0.61.5 => 0.61.5
  npmGlobalPackages:
    react-native-cli: 2.0.1
    react-native-startup-time: 1.2.1
- **Platform that you're experiencing the issue on**: - [ ] iOS - [x] Android - [ ] **iOS** but have not tested behavior on Android - [x ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `6.7.1` - **Are you using `TypeScript`?** - `Y/N` & `Y`




Most helpful comment

Yeah, as I said before the error happened only on the first install and launch the application. After the first lunch, even v6.7.1 doesn't cause force close. at least it's what I'm experiencing with my project.

I suggest to uninstall your application and reinstall it and see whether the problem is still happening.

All 10 comments

Facing this issue as well. Downgrading from @react-native-firebase/messaging 6.7.1 to 6.7.0 is a possible workaround for now.

I think there may be a PR out for this, on my phone though and can't find it.

@Ehesp

I'm facing with this crash only on application first install and first lunch. it causes a force close in release mode too.

PR #3552 has been merged which should fix this, will be published later today.

PR #3552 has been merged which should fix this, will be published later today.

@Salakar
please publish the new version, we are still waiting. Thanks

Facing this issue as well. Downgrading from @react-native-firebase/messaging 6.7.1 to 6.7.0 is a possible workaround for now.

I downgraded to many versions including 6.7.0, even version 6.4.0 suffers from this issue.

@SaeedZhiany are you sure? I downgraded to 6.7.0 and it seemed to resolve the issue. Make sure you clear the gradle cache when downgrading.

Yeah, as I said before the error happened only on the first install and launch the application. After the first lunch, even v6.7.1 doesn't cause force close. at least it's what I'm experiencing with my project.

I suggest to uninstall your application and reinstall it and see whether the problem is still happening.

Actually I just uninstalled/reinstalled and it did crash again for me on 6.7.0. Any word on when this release will be available @Salakar?

RNFB v7.01 is out

I'm going to check whether the problem is gone. I'll report back here.

Update:
I can confirm the problem has been fixed in RNFB v7.x.x

Was this page helpful?
0 / 5 - 0 ratings