facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
117.12k stars 24.07k forks source link

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

Open edstbbz opened 12 months ago

edstbbz commented 12 months ago

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:

Steps to reproduce

1) start project 2) connect to chrome debugger

screen

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

-

emanuelasistensi commented 12 months ago

same problem here

emanuelasistensi commented 12 months ago

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

AshlandWest commented 11 months ago

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

Danushka50 commented 11 months ago
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
kitety commented 11 months ago

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

gabrielmenezesnog commented 11 months ago

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

tlt254 commented 11 months ago

Me too

nicson0427 commented 11 months ago

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

cheikhsidi commented 11 months ago

Any update on this issue?

arrywu commented 10 months ago

Me too! Could anyone help us?

a7madgamal commented 10 months ago

Any feedback about this is appreciated

Dror-Bar commented 10 months ago

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.

Jabed-Akhtar commented 10 months ago

react version: 18.2.0 react-native version: 0.72.4

error

chenweigh commented 10 months ago

same problem +1

and the solution:

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

Gagik-arch commented 9 months ago

I have the some problem.

iriscoopers commented 9 months ago

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

gusilveiramp commented 9 months ago

+1

jehillert commented 9 months ago

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.

lazaro-contato commented 8 months ago

updates?

valery-lavrik commented 8 months ago

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

Mr-BeanSir commented 8 months ago

The same problem occurs

lazaro-contato commented 8 months ago

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.

sivamani-edumpus commented 8 months ago

Same propelem me image

XilinJia commented 8 months ago

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.

ck837 commented 8 months ago

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!

wieckowskimateusz commented 8 months ago

same in RN 0.72.6

t-fritsch commented 7 months ago

@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 😅

williamgurzoni commented 7 months ago

@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.

afcanop commented 5 months ago

+1

brownieboy commented 5 months ago

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 commented 5 months ago

For me, this package worked to re-enable Remote Debugging under RN 0.73.2 https://github.com/gusgard/react-native-devsettings.

It seems to be a wrapper around the NativeDevSettings method, but it doesn't crash my app!

Lakston commented 1 month ago

still facing this issue in RN 0.73.8, what are we supposed to do to debug ? Flipper is dead, we cant use react native debugger because of this, so what now ?

MyNetdisk commented 1 month ago

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.

van8tka commented 1 week ago

same problem

it's continius on 0.74.2