react-native icon indicating copy to clipboard operation
react-native copied to clipboard

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

Open edstbbz opened this issue 11 months ago • 34 comments

Description

After update to 0.72.2 and connect to chrome debugger an error appears:

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.

React Native Version

0.72.2

Output of npx react-native info

System: OS: macOS 13.4.1 CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 2.95 GB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 16.13.0 path: /usr/local/bin/node Yarn: version: 3.2.1 path: /usr/local/bin/yarn npm: version: 8.1.0 path: /usr/local/bin/npm Watchman: version: 2022.10.24.00 path: /usr/local/bin/watchman Managers: CocoaPods: Not Found SDKs: iOS SDK: Platforms: - DriverKit 21.4 - iOS 16.0 - macOS 12.3 - tvOS 16.0 - watchOS 9.0 Android SDK: Not Found IDEs: Android Studio: 2022.2 AI-222.4459.24.2221.10121639 Xcode: version: 14.0.1/14A400 path: /usr/bin/xcodebuild Languages: Java: version: 11.0.11 path: /usr/bin/javac Ruby: version: 2.6.5 path: /Users/user/.rvm/rubies/ruby-2.6.5/bin/ruby npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.2 wanted: 0.72.2 react-native-macos: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: false newArchEnabled: false

Steps to reproduce

  1. start project
  2. connect to chrome debugger screen

Snack, code example, screenshot, or link to a repository

edstbbz avatar Jul 12 '23 10:07 edstbbz

same problem here

emanuelasistensi avatar Jul 12 '23 15:07 emanuelasistensi

Captura de pantalla 2023-07-12 a la(s) 2 03 12 p  m Captura de pantalla 2023-07-12 a la(s) 2 04 14 p  m Same problem here, I leave evidence: project recently created with react-native 0.72.3

emanuelasistensi avatar Jul 12 '23 18:07 emanuelasistensi

Replicated on fresh install of RN 72.3, but app seems to run okay after throwing error.

AshlandWest avatar Jul 14 '23 19:07 AshlandWest

Screenshot 2023-07-17 at 2 43 14 PM Reproduced in RN 72.3.... Any Solution!!!

Also got below error in console

Error: Unable to resolve module ./debugger-ui/debuggerWorker.aca173c4 from /Users/******/******/*******/.: 

None of these files exist:
  * debugger-ui/debuggerWorker.aca173c4(.native|.native.js|.js|.native.jsx|.jsx|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
  * debugger-ui/debuggerWorker.aca173c4/index(.native|.native.js|.js|.native.jsx|.jsx|.native.json|.json|.native.ts|.ts|.native.tsx|.tsx)
    at ModuleResolver.resolveDependency (/Users/******/******/*******/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:114:15)
    at DependencyGraph.resolveDependency (/Users/******/******/*******/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
    at /Users/******/******/*******/WordsPuzzelGame/node_modules/metro/src/lib/transformHelpers.js:169:21
    at Server._resolveRelativePath (/Users/******/******/*******/node_modules/metro/src/Server.js:1045:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Server._explodedSourceMapForBundleOptions (/Users/******/******/*******/node_modules/metro/src/Server.js:993:35)
    at async Promise.all (index 1)
    at async Server._symbolicate (/Users/******/******/*******/node_modules/metro/src/Server.js:945:26)
    at async Server._processRequest (/Users/******/******/*******/node_modules/metro/src/Server.js:418:7)
 LOG  JavaScript logs will appear in your browser console

Danushka50 avatar Jul 17 '23 09:07 Danushka50

I also encountered the same problem, but I don't know how to solve it. "react-native": "0.72.3"

kitety avatar Aug 06 '23 04:08 kitety

same. I've created a new project with react-native v0.72.3 and still get this problem.

gabrielmenezesnog avatar Aug 08 '23 19:08 gabrielmenezesnog

Me too

tlt254 avatar Aug 09 '23 03:08 tlt254

is this gonna affect prod? or is just debug will prompt this error and doesnt affect other code

nicson0427 avatar Aug 10 '23 10:08 nicson0427

Any update on this issue?

cheikhsidi avatar Aug 12 '23 19:08 cheikhsidi

Me too! Could anyone help us?

arrywu avatar Aug 18 '23 11:08 arrywu

Any feedback about this is appreciated

a7madgamal avatar Aug 21 '23 14:08 a7madgamal

Is there any way to remove this red warning?

Edit: Following this answer, I changed callNativeSyncHook in the file node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js like this:

callNativeSyncHook(
    moduleID: number,
    methodID: number,
    params: mixed[],
    onFail: ?(...mixed[]) => void,
    onSucc: ?(...mixed[]) => void,
  ): mixed {
    this.processCallbacks(moduleID, methodID, params, onFail, onSucc);
    if (global.nativeCallSyncHook) return global.nativeCallSyncHook(moduleID, methodID, params);
  }

and saved it with patch-package. This seems to have fixed all error messages.

Dror-Bar avatar Aug 22 '23 13:08 Dror-Bar

react version: 18.2.0 react-native version: 0.72.4

error

Jabed-Akhtar avatar Aug 26 '23 10:08 Jabed-Akhtar

same problem +1

and the solution:

https://stackoverflow.com/questions/61067004/invariant-violation-calling-synchronous-methods-on-native-modules-is-not-suppor

chenweigh avatar Sep 01 '23 03:09 chenweigh

I have the some problem.

Gagik-arch avatar Sep 22 '23 12:09 Gagik-arch

Ran into it as well, but the docs state remote debugging in Chrome is deprecated since 0.72

Copy pasting from the docs:

If your project still relies on this feature, you can manually enable it manually through the NativeDevSettings.setIsDebuggingRemotely function.

import NativeDevSettings from 'react-native/Libraries/NativeModules/specs/NativeDevSettings';
export default function App() {
  useEffect(() => {
    NativeDevSettings.setIsDebuggingRemotely(true);
  }, []);

  return <MyApp />;
}

Haven't tried it myself but hope this helps

iriscoopers avatar Sep 22 '23 13:09 iriscoopers

+1

gusilveiramp avatar Sep 24 '23 23:09 gusilveiramp

So wait, does this mean in the future we are going to be stuck with flipper? I got nothing against it. It's just rn-debugger fits like a glove. I've tried probably 5-6 times now to get used to the alternatives and they just aren't as comfortable.

jehillert avatar Oct 03 '23 12:10 jehillert

updates?

lazaro-contato avatar Oct 16 '23 14:10 lazaro-contato

The documentation says that this is specially done, but you can disable it

NativeDevSettings.setIsDebuggingRemotely(true);

But once you enable this option, the application starts to restart endlessly

valery-lavrik avatar Oct 17 '23 07:10 valery-lavrik

The same problem occurs

Mr-BeanSir avatar Oct 23 '23 05:10 Mr-BeanSir

I tried many solutions about this and nothing works. For me the solution was to install Flipper (https://fbflipper.com/) and debug the entire project with it. For some reason React Native Debbugger doesn't work very well with React Reanimated.

lazaro-contato avatar Oct 23 '23 12:10 lazaro-contato

Same propelem me image

sivamani-edumpus avatar Oct 27 '23 12:10 sivamani-edumpus

same problem +1

and the solution:

https://stackoverflow.com/questions/61067004/invariant-violation-calling-synchronous-methods-on-native-modules-is-not-suppor

that doesn't work for me.

XilinJia avatar Oct 28 '23 14:10 XilinJia

Is there any way to remove this red warning?有什么办法可以去掉这个红色警告吗?

Edit: 编辑: Following this answer, I changed callNativeSyncHook in the file node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js like this:根据这个答案,我在文件 node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js 中更改了 callNativeSyncHook ,如下所示:

callNativeSyncHook(
    moduleID: number,
    methodID: number,
    params: mixed[],
    onFail: ?(...mixed[]) => void,
    onSucc: ?(...mixed[]) => void,
  ): mixed {
    this.processCallbacks(moduleID, methodID, params, onFail, onSucc);
    if (global.nativeCallSyncHook) return global.nativeCallSyncHook(moduleID, methodID, params);
  }

and saved it with patch-package. This seems to have fixed all error messages.并将其与补丁包一起保存。这似乎已经修复了所有错误消息。

I try this and it succeeds.No error msg! Thanks bro!

ck837 avatar Nov 01 '23 08:11 ck837

same in RN 0.72.6

wieckowskimateusz avatar Nov 09 '23 10:11 wieckowskimateusz

@lazaro-contato The problem with Flipper is that last year, in their 2022 survey, RN team said that flipper wasn't the right tool anymore and that they were working on better debugging tools "that meets our standard"

So flipper isn't the right tool (it's sad because it was promising, having native debug tools like logcat, etc. alongside with react and js devtools is a great idea, but it's so heavy and buggy that I must agree with the RN team on this point). But in the same time chrome debugging is suffering from this bug since months with apparently no intention from the team to work on it.

I hope the new debug tools will arrive very soon, debugging XP in RN is such a major pain point

Edit: with react native debugger, the error still shows-up in devtools console but apparently not in the in-app Logbox. A little less annoying 😅

t-fritsch avatar Nov 12 '23 21:11 t-fritsch

@lazaro-contato The problem with Flipper is that last year, in their 2022 survey, RN team said that flipper wasn't the right tool anymore and that they were working on better debugging tools "that meets our standard"

So flipper isn't the right tool (it's sad because it was promising, having native debug tools like logcat, etc. alongside with react and js devtools is a great idea, but it's so heavy and buggy that I must agree with the RN team on this point). But in the same time chrome debugging is suffering from this bug since months with apparently no intention from the team to work on it.

I hope the new debug tools will arrive very soon, debugging XP in RN is such a major pain point

Edit: with react native debugger, the error still shows-up in devtools console but apparently not in the in-app Logbox. A little less annoying 😅

100% what @t-fritsch said. Debugging is such a pain point.

williamgurzoni avatar Nov 29 '23 23:11 williamgurzoni

+1

afcanop avatar Jan 17 '24 15:01 afcanop

Ran into it as well, but the docs state remote debugging in Chrome is deprecated since 0.72

Copy pasting from the docs:

If your project still relies on this feature, you can manually enable it manually through the NativeDevSettings.setIsDebuggingRemotely function.

import NativeDevSettings from 'react-native/Libraries/NativeModules/specs/NativeDevSettings';
export default function App() {
  useEffect(() => {
    NativeDevSettings.setIsDebuggingRemotely(true);
  }, []);

  return <MyApp />;
}

Haven't tried it myself but hope this helps

This crashed my app every time. Presumably, others here had the same experience, hence all the thumbs' down.

brownieboy avatar Feb 04 '24 06:02 brownieboy