react-native - 不变违规: Calling synchronous methods on native modules is not supported in Chrome

标签 react-native

我已经 fork 了这个React库以与React Native一起使用,并通过安装react-native-svguse-elapsed-time和prop-types使它起作用:

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

但是我现在无法使用调试器:

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)



我一直在高低搜索有关可能导致错误的软件包的任何线索,我只能看到报告的与react-native-device-info相关的问题,但这不会引起问题。该错误是什么意思,如果周围只有很少的信息,我该如何开始调试它?

最佳答案

这是临时修复。这在我这边工作得很好。您必须编辑此文件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);
    }
  }
您还可以使用patch-package对其进行永久性修补。
underlaying issue

关于react-native - 不变违规: Calling synchronous methods on native modules is not supported in Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61067004/

相关文章:

android - 使用 firebase 创建群组聊天 react-native

android - 我如何在 react-native 中保持在后台杀死的 android 应用程序的状态

由于添加 react-native-google-place-picker 节点模块,React-Native 应用程序将无法编译

reactjs - Expo React 警告 : Can't perform a React state update on an unmounted component. 这是一个空操作,但它表明您的应用程序中存在内存泄漏

javascript - 如何在外部npm包中使用React的Link组件而不出现错误: invariant "you should not use link outside router"

ios - 如果应用程序是使用 react-native 构建的,如何在 iOS 的 "Open in"对话框中注册应用程序?

ios - react native : What is the difference between running app with Xcode vs `react-native run-ios` ?

react-native - 修复错误 : unable to resolve module './index.android' from ' '

ios - 过多的挂起回调 : 501. 一些挂起的回调可能已经泄露

javascript - map 内匿名函数内的方法未定义