Search code examples
react-native

Invariant Violation: Calling synchronous methods on native modules is not supported in Chrome


I have forked this React library for use with React Native and have got it working by installing react-native-svg, use-elapsed-time and prop-types:

https://github.com/vydimitrov/react-countdown-circle-timer

However I now am not able to use the debugger:

Invariant Violation: Calling synchronous methods on native modules is not supported in Chrome.

Consider providing alternative methods to expose this method in debug mode, e.g. by exposing constants ahead-of-time.

This error is located at: in CountdownCircleTimer (at AppRoot.js:118) in AppRoot (at App.js:9) in Provider (at App.js:8) in App (at renderApplication.js:40) in RCTView (at AppContainer.js:101) in RCTView (at AppContainer.js:119)

I have searched high and low for any clues as to which package could be causing the error and I can only see the issue reported relating to react-native-device-info but this is not causing the problem. What does the error mean an how can I begin to debug this if there is such little information around about it?


Solution

  • This is temporary fix. This is working perfectly on my side. you have to edit this file

    node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js

    callNativeSyncHook(
        moduleID: number,
        methodID: number,
        params: any[],
        onFail: ?Function,
        onSucc: ?Function,
      ): any {
        const isDebuggingEnabled = (typeof atob !== 'undefined');
        this.processCallbacks(moduleID, methodID, params, onFail, onSucc);
        if(!isDebuggingEnabled)
        {
          return global.nativeCallSyncHook(moduleID, methodID, params);
        }
      }
    

    you can also use patch-package to patch it permanently.

    underlaying issue