react-native: E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules

To Reproduce

1.Setup release configurations. 2.Connect a device and run react-native run-android --variant=release or cd android && gradlew 3.assembleRelease. And this exception occurs:

2019-08-10 10:59:59.231 11304-11434/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
    Process: com.baojuchengapp, PID: 11304
    com.facebook.react.common.JavascriptException: console.assert is not a function. (In 'console.assert(null!=o,"'this' is expected an Event object, but got",n)', 'console.assert' is undefined), stack:
    o@112:173
    w@112:1841
    dispatchEvent@112:5597
    value@111:6130
    value@111:2835
    value@44:1280
    value@23:3518
    <unknown>@23:822
    value@23:2772
    value@23:794
    value@-1
        at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:54)
        at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:38)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:158)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:101)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:166)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:784)

package.json:

{
  "name": "baojucheng",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@ant-design/react-native": "^3.1.11",
    "@react-native-community/async-storage": "^1.6.1",
    "@tradle/react-native-http": "^2.0.1",
    "assert": "^1.5.0",
    "browserify-zlib": "^0.1.4",
    "console-browserify": "^1.1.0",
    "constants-browserify": "^1.0.0",
    "crypto-js": "^3.1.9-1",
    "dns.js": "^1.0.1",
    "domain-browser": "^1.2.0",
    "events": "^1.1.1",
    "https-browserify": "0.0.1",
    "md5": "^2.2.1",
    "mobx": "^3.3.1",
    "mobx-react": "^4.3.4",
    "moment": "^2.24.0",
    "node-emoji": "^1.10.0",
    "path-browserify": "0.0.0",
    "punycode": "^1.4.1",
    "query-string": "^6.8.2",
    "querystring-es3": "^0.2.1",
    "react": "16.8.6",
    "react-native": "0.60.4",
    "react-native-amap-geolocation": "^1.0.4",
    "react-native-amap3d": "^1.1.1",
    "react-native-audio": "^4.3.0",
    "react-native-camera": "^3.0.0",
    "react-native-contacts": "^5.0.2",
    "react-native-crypto": "^2.1.2",
    "react-native-device-info": "^2.3.2",
    "react-native-fs": "^2.14.1",
    "react-native-level-fs": "^3.0.1",
    "react-native-os": "^1.2.4",
    "react-native-permissions": "^1.2.0",
    "react-native-picker": "^4.3.7",
    "react-native-puti-pay": "^1.3.0",
    "react-native-qrcode-svg": "^5.1.2",
    "react-native-randombytes": "^3.5.3",
    "react-native-router-flux": "^4.0.0-beta.31",
    "react-native-sectionlist-contacts": "^1.1.3",
    "react-native-shadow": "^1.2.2",
    "react-native-sound": "^0.11.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^9.5.3",
    "react-native-swipe-list-view": "^2.0.0",
    "react-native-swiper": "^1.5.14",
    "react-native-syan-image-picker": "^0.3.7",
    "react-native-tcp": "^3.3.1",
    "react-native-udp": "^2.6.1",
    "react-native-uuid": "^1.4.9",
    "react-native-webview": "^5.12.1",
    "react-native-zip-archive": "^4.1.1",
    "react-navigation": "^1.5.8",
    "readable-stream": "^1.0.33",
    "realm": "^2.29.1",
    "rn-fetch-blob": "^0.10.16",
    "stream": "0.0.2",
    "stream-browserify": "^1.0.0",
    "string_decoder": "^0.10.31",
    "teaset": "^0.6.3",
    "timers": "^0.1.1",
    "timers-browserify": "^1.4.2",
    "tty-browserify": "0.0.0",
    "url": "^0.10.3",
    "util": "^0.12.1",
    "vm-browserify": "0.0.4",
    "xml2js": "^0.4.19"
  },
  "devDependencies": {
    "@babel/core": "^7.5.5",
    "@babel/plugin-proposal-decorators": "^7.4.4",
    "@babel/preset-env": "^7.5.5",
    "@babel/runtime": "^7.5.5",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.8.0",
    "babel-plugin-transform-class-properties": "^6.24.1",
    "babel-plugin-transform-decorators-legacy": "^1.3.5",
    "eslint": "^6.1.0",
    "jest": "^24.8.0",
    "metro-react-native-babel-preset": "^0.55.0",
    "react-test-renderer": "16.8.6",
    "rn-nodeify": "github:tradle/rn-nodeify"
  },
  "jest": {
    "preset": "react-native"
  },
  "react-native": {
    "zlib": "browserify-zlib",
    "console": "console-browserify",
    "constants": "constants-browserify",
    "crypto": "react-native-crypto",
    "dns": "dns.js",
    "net": "react-native-tcp",
    "domain": "domain-browser",
    "http": "@tradle/react-native-http",
    "https": "https-browserify",
    "os": "react-native-os",
    "path": "path-browserify",
    "querystring": "querystring-es3",
    "fs": "react-native-level-fs",
    "_stream_transform": "readable-stream/transform",
    "_stream_readable": "readable-stream/readable",
    "_stream_writable": "readable-stream/writable",
    "_stream_duplex": "readable-stream/duplex",
    "_stream_passthrough": "readable-stream/passthrough",
    "dgram": "react-native-udp",
    "stream": "stream-browserify",
    "timers": "timers-browserify",
    "tty": "tty-browserify",
    "vm": "vm-browserify",
    "tls": false
  },
  "browser": {
    "zlib": "browserify-zlib",
    "console": "console-browserify",
    "constants": "constants-browserify",
    "crypto": "react-native-crypto",
    "dns": "dns.js",
    "net": "react-native-tcp",
    "domain": "domain-browser",
    "http": "@tradle/react-native-http",
    "https": "https-browserify",
    "os": "react-native-os",
    "path": "path-browserify",
    "querystring": "querystring-es3",
    "fs": "react-native-level-fs",
    "_stream_transform": "readable-stream/transform",
    "_stream_readable": "readable-stream/readable",
    "_stream_writable": "readable-stream/writable",
    "_stream_duplex": "readable-stream/duplex",
    "_stream_passthrough": "readable-stream/passthrough",
    "dgram": "react-native-udp",
    "stream": "stream-browserify",
    "timers": "timers-browserify",
    "tty": "tty-browserify",
    "vm": "vm-browserify",
    "tls": false
  }
}

react-native info show:

warn The following packages use deprecated "rnpm" config that will stop working from next release:
  - react-native-amap-geolocation: https://github.com/qiuxiang/react-native-amap-geolocation#readme
  - react-native-amap3d: https://github.com/qiuxiang/react-native-amap3d#readme
  - react-native-zip-archive: https://github.com/mockingbot/react-native-zip-archive
  - realm: https://realm.io
  - rn-fetch-blob: https://github.com/joltup/rn-fetch-blob#readme
Please notify their maintainers about it. You can find more details at https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide.
info Fetching system and libraries information...
System:
    OS: Linux 3.10 CentOS Linux 7 (Core)
    CPU: (4) x64 Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
    Memory: 140.26 MB / 7.07 GB
    Shell: 4.2.46 - /bin/bash
  Binaries:
    Node: 8.10.0 - /usr/local/bin/node
    Yarn: 1.16.0 - /usr/bin/yarn
    npm: 5.6.0 - /usr/local/bin/npm
    Watchman: 4.7.0 - /usr/local/bin/watchman
  SDKs:
    Android SDK:
      API Levels: 23, 24, 26, 27, 28, 29
      Build Tools: 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3
      System Images: android-28 | Android TV Intel x86 Atom, android-28 | Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64, android-29 | Intel x86 Atom
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60.4 => 0.60.4

What’s the reason for this, the first time I met

@react-native-bot

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 18 (1 by maintainers)

Most upvoted comments

I am facing the same error but different reason:

FATAL EXCEPTION: mqt_native_modules
java.lang.ClassCastException: com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.String

My app is running in dev apk but crash upon start in release apk. Have you guys faced the same issue before?

I am on RN 0.63.2 😦

got the same error, Caused my app to crash. @umairda thanks you ,it worked for me, you save my day!

i add this code in the index.js flle, This temporarily solved my problem.

if (!__DEV__) {
        global.console = {
            info: () => {},
            log: () => {},
            assert: () => {},
            warn: () => {},
            debug: () => {},
            error: () => {},
            time: () => {},
            timeEnd: () => {},
        };
    }

I got this same error. I investigated the call stack from my sourcemap file and got this:

*** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: console.assert is not a function. (In 'console.assert(null!=o,"'this' is expected an Event object, but got",n)', 'console.assert' is undefined)', reason: 'Unhandled JS Exception: console.assert is not a function. (In 'console.assert(null!=o,"'this' is expected an Event object, but got",n)', 'console.assert' is undefined), stack:
at ./s/event-target-shim/dist/event-target-shim.js:47:16
  at event (./s/event-target-shim/dist/event-target-shim.js:487:7)
  at wrappedEvent (./s/event-target-shim/dist/event-target-shim.js:813:16)
  at dispatchEvent (./s/react-native/Libraries/Network/XMLHttpRequest.js:577:13)
  at this (./s/react-native/Libraries/Network/XMLHttpRequest.js:388:25)
  at subscription (./s/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12)
  at moduleMethods (./s/react-native/Libraries/BatchedBridge/MessageQueue.js:395:47)
  at module (./s/react-native/Libraries/BatchedBridge/MessageQueue.js:106:26)
  at fn (./s/react-native/Libraries/BatchedBridge/MessageQueue.js:343:8)
  at ./s/react-native/Libraries/BatchedBridge/MessageQueue.js:105:17

I opened up node_modules/event-target-shim/dist/event-target-shim.js and found a console.assert statement

I use the transform-remove-console babelrc plugin but out of paranoia (or some other old problem that I can’t remember) I manually remove the console statements with the following file:

import { Platform } from "react-native"

if (!__DEV__ && Platform.OS !== "android") {
  try {
    console = {}
    console.assert = () => {}
    console.info = () => {}
    console.log = () => {}
    console.warn = () => {}
    console.error = () => {}
    console.time = () => {}
    console.timeEnd = () => {}

    global.console = console
  } catch (err) {}
}

I basically added console.assert above and now my app doesn’t crash anymore. I reviewed my app commit history between this failing build and the previous stable build and I’m not sure what I did to trigger this sudden console.assert error

if (!__DEV__) {
  for (const iterator of Object.keys(global.console)) {
    global.console[iterator] = () => 0;
  }
}

@Aung-Myint-Thein Could you please provide more information about the function that was deprecated in Sentry that you changed?

Actually, I updated my Sentry and one of the functions is deprecated and hence the crash happens. Interestingly, the function is called only __DEV__ is false. So, this crash happened only in release build. So, I fixed the function and it solved my problem.

The method I used is I git revert back to the last point my release build is working fine. Then I slowly traced back the changes. Usually, this kind of crash happens in my 3rd party library updates since the crash by your codes should be able to seen while testing or running in dev mode.

Hope this help 🙂

I think it is better like this:

if (!__DEV__) {
  global.console = {
    ...console,
    info: () => {},
    log: () => {},
    warn: () => {},
    debug: () => {},
    error: () => {}
  };
}

@lanss315425 Did you solve this?