问题描述
在本地调react-native项目的时候,打开chrome debugger模式的时候,发现控制台报错,导致不能在浏览器使用debug:
Invariant Violation: Calling synchronous methods on native modules is not supported in Chrome
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)
解决方案:
编辑文件: 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);
}
}
PS:当你的项目重新更新了依赖,记得重新替换上述代码~
原文链接:链接