software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
5.85k stars 954 forks source link

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. #2749

Closed LayMui closed 2 months ago

LayMui commented 3 months ago

Description

<GestureHandlerRootView cause error when running unit test with jest

Steps to reproduce

yarn to install all dependencies

run yarn test -u

throw out these error FAIL my-design-system-react-native libs/ahua-design-system-react-native/src/tests/BottomSheet.test.js ● Test suite failed to run

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","DeviceInfo","KeyboardObserver","I18nManager"],"TurboModules":[],"NotFound":["NativeAnimatedModule","SoundManager","FrameRateLogger","RNGestureHandlerModule"]}

  1 | import React, { forwardRef } from 'react';
  2 | import { Dimensions } from 'react-native';
> 3 | import { Modalize, ModalizeProps } from 'react-native-modalize';

this was ok with RN 0.72.3 and "react-native-gesture-handler": "^2.9.0",

Snack or a link to a repository

https://github.com/LayMui/ahuaAppTesting

Gesture Handler version

2.15.0

React Native version

0.73.2

Platforms

MacOS

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

None

Device model

NA

Acknowledgements

Yes

IvanRuch commented 3 months ago

I had the same problem

cd ios pod install cd ..

solved the problem for me

LayMui commented 3 months ago

@IvanRuch what is your RN version? if it's 0.72.3 it will work for me but not 0.73.2

LayMui commented 3 months ago

Hey! πŸ‘‹

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

unable to show the private repo as it's quite huge but i have provided the code snippet as above. just wonder if this react-native-gesture-handler 2.15.0 is compatible with the new latest RN version 0.73.2?

LayMui commented 3 months ago

the complete error is Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","DeviceInfo","KeyboardObserver","I18nManager"],"TurboModules":[],"NotFound":["NativeAnimatedModule","SoundManager","FrameRateLogger","RNGestureHandlerModule"]}

LayMui commented 3 months ago

hi, I have provided the minimal repo at https://github.com/LayMui/ahuaAppTesting

please take a look this is an issue when running yarn test -u or yarn test

LayMui commented 3 months ago

could this be due to this PR not merged? https://github.com/software-mansion/react-native-gesture-handler/pull/2724

RafaPatino01 commented 3 months ago

I'm having the same issue here

*** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.', reason: 'Unhandled JS Exception: Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registere..., stack:

AnYuku commented 2 months ago

I'm having the same issue here. It happed after i installed @react-navigation/drawer, cmd: "npm install @react-navigation/drawer", my react native version is 0.73

denlahodnyi commented 2 months ago

I had the same issue when running my tests. This solution (link) from React Navigation docs helped me to resolve it.

setup-jest.js

import 'react-native-gesture-handler/jestSetup';

jest.config.js

{
  "setupFiles": [
    "<rootDir>/setup-jest.js"
  ],
}
mikey18 commented 2 months ago

i have a very similar issue too

ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","LogBox","SourceCode","Timing","AppState","BlobModule","WebSocketModule","DevSettings","DevToolsSettingsManager","Networking","Appearance","DevLoadingView","HeadlessJsTaskSupport","DeviceInfo","UIManager","DeviceEventManager","RNCSafeAreaContext","NativeAnimatedModule","SoundManager","I18nManager","StatusBarManager","StatusBarManager","ImageLoader"],"TurboModules":[],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","RedBox","BugReporting","FrameRateLogger","KeyboardObserver","RNGestureHandlerModule"]}, js engine: hermes

ERROR Invariant Violation: "main" has not been registered. This can happen if:

I am using expo development Build; i have rebuilt the app so many times, cleared my cache, and nothing works

im using a windows PC. Please, has anyone faced this issue and gotten a fix?, i've been trying to debug this thig for a week now, and i'm seriously getting tired of React Native at this point, more of debugging than actual productivity.

Mary-Grigoryan commented 2 months ago

I am having the same issue too. Tried to use react native gesture handler version < 2.15.0 and still didn't work. I have ran pod install too. I'm also on RN version 0.73.4.

mikey18 commented 2 months ago

I fixed it. React Native gesture handler version < 2.15.0 doesn't work with the latest React Native, so I downgraded React Native gesture handler to version < 2.14.0.

Mary-Grigoryan commented 2 months ago

Thank you, just did that and the error went away

mikey18 commented 2 months ago

very happy to hear thatπŸ‘Œ

LayMui commented 2 months ago

mikey18 what version of react-native-gesture-handler are you using? 2.13.4 it still give that error Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":[],"TurboModules":[],"NotFound":["RNGestureHandlerModule"]}

this is an issue of react-native-gesture-handler with jest rather than the latest RN version, right?

mikey18 commented 2 months ago

Hey LayMui, I'm not sure if the issue is rather with Jest or the RN version itself, but I was using react-native-gesture-handler 2.15.0, which was causing the error, then I downgraded to react-native-gesture-handler 2.14.0, and it stopped showing the error, and I'm using the latest RN.

LayMui commented 2 months ago

it still fail FAIL src/tests/BottomSheet.test.js ● Test suite failed to run

       Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":[],"TurboModules":[],"NotFound":["RNGestureHandlerModule"]}

         1 | import 'react-native';
       > 2 | import 'react-native-gesture-handler';
           | ^
         3 | import renderer, { act } from 'react-test-renderer';
         4 | import { AhuaText } from '../lib/AhuaText';
         5 | import { BottomSheet } from '../lib/BottomSheet';
LayMui commented 2 months ago

here is my package.json

"dependencies": { "react-native-pager-view": "^6.1.2", "react-native-gesture-handler": "^2.14.0",

mikey18 commented 2 months ago

try using 'npx expo-doctor' to see what is causing the conflicts

LayMui commented 2 months ago

my project don't use expo. is there any other command I can use? I used 2.14.0 or 2.15.0 I saw the same error once I have this line import 'react-native-gesture-handler';

denlahodnyi commented 2 months ago

@LayMui Have you tried my solution? Or the same one, but from the gesture-handler docs. I should have mocked gesture-handler to run my tests. Maybe it'll help you too.

LayMui commented 2 months ago

my file is test-setup.js I add the line import 'react-native-gesture-handler/jestSetup';

import '@testing-library/jest-native/extend-expect';
import 'react-native-gesture-handler/jestSetup';

here is the jest.config.ts module.exports = { displayName: 'react-native-app', preset: 'react-native', resolver: '@nx/jest/plugins/resolver', moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'], setupFilesAfterEnv: ['/test-setup.ts'], moduleNameMapper: { '\.svg$': '@nx/react-native/plugins/jest/svg-mock', }, coverageDirectory: '../../coverage/apps/react-native-app', };

but still the same error

at Object.require (src/tests/BottomSheet.test.js:2:1)

PASS react-native-app apps/react-native-app/src/app/App.spec.tsx (23.393 s) A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks. Active timers can also cause this, ensure that .unref() was called on them.

Summary of all failing tests FAIL libs/ahua-design-system-react-native/src/tests/BottomSheet.test.js ● Test suite failed to run

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":[],"TurboModules":[],"NotFound":["RNGestureHandlerModule"]}

  1 | import 'react-native';
> 2 | import 'react-native-gesture-handler';
    | ^
  3 | import renderer, { act } from 'react-test-renderer';
  4 | import { AhuaText } from '../lib/AhuaText';
  5 | import { BottomSheet } from '../lib/BottomSheet';

  at invariant (../../node_modules/invariant/invariant.js:40:15)
  at Object.getEnforcing (../../node_modules/react-native/Libraries/TurboModule/TurboModuleRegistry.js:87:12)
  at Object.getEnforcing (../../node_modules/react-native-gesture-handler/lib/commonjs/specs/NativeRNGestureHandlerModule.ts:26:36)
  at Object.<anonymous> (../../node_modules/react-native-gesture-handler/lib/commonjs/RNGestureHandlerModule.ts:4:1)
  at Object.<anonymous> (../../node_modules/react-native-gesture-handler/lib/commonjs/init.ts:2:1)
  at Object.<anonymous> (../../node_modules/react-native-gesture-handler/lib/commonjs/index.ts:1:1)
  at Object.require (src/tests/BottomSheet.test.js:2:1)
LayMui commented 2 months ago

I use "react-native-gesture-handler": "2.9.0",

plus add the import 'react-native-gesture-handler/jestSetup'; to test.setup.ts still having this error

       Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":[],"TurboModules":[],"NotFound":["RNGestureHandlerModule"]}
Princejain21 commented 2 months ago

@mikey18 have you resolve this error?

i have a very similar issue too

ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","LogBox","SourceCode","Timing","AppState","BlobModule","WebSocketModule","DevSettings","DevToolsSettingsManager","Networking","Appearance","DevLoadingView","HeadlessJsTaskSupport","DeviceInfo","UIManager","DeviceEventManager","RNCSafeAreaContext","NativeAnimatedModule","SoundManager","I18nManager","StatusBarManager","StatusBarManager","ImageLoader"],"TurboModules":[],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","RedBox","BugReporting","FrameRateLogger","KeyboardObserver","RNGestureHandlerModule"]}, js engine: hermes

ERROR Invariant Violation: "main" has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it, and restart it in the current project.
  • A module failed to load due to an error, and AppRegistry.registerComponent wasn't called., js engine: hermes

I am using expo development Build; i have rebuilt the app so many times, cleared my cache, and nothing works

im using a windows PC. Please, has anyone faced this issue and gotten a fix?, i've been trying to debug this thig for a week now, and i'm seriously getting tired of React Native at this point, more of debugging than actual productivity.

please guide me to be resolve this?

j-piasecki commented 2 months ago

The only way I am able to reproduce this issue is without properly configuring jest mocks. Can you prepare a minimal reproduction with gesture handler mocks configured where this problem occurs?

LayMui commented 2 months ago

could this be due to this PR not merged? #2724

This issue appears in RN 0.73.x with the new fabric architecture changes But does not exist in 0.72.x

LayMui commented 2 months ago

my framework is using nx.let me try to setup one mini repo for that...

PhamQuyet1606 commented 2 months ago

Hello @LayMui, Have you fixed this problem? Im using Nx too, and Im finding the solution for this one :(

LayMui commented 2 months ago

yes. my colleague has fixed it add this line

  setupFiles: ["../../node_modules/react-native-gesture-handler/jestSetup.js"],
};

to

module.exports = {
  displayName: 'xxx-system-react-native',
  preset: 'react-native',
  resolver: '@nx/jest/plugins/resolver',
  moduleFileExtensions: ['ts', 'js', 'html', 'tsx', 'jsx'],
  setupFilesAfterEnv: ['<rootDir>/test-setup.ts'],
  moduleNameMapper: {
    // '.svg': '@nx/react-native/plugins/jest/svg-mock',
  },
  transformIgnorePatterns: [
  'node_modules/(?!(@react-native|react-native|react-native-calendars|react-native-swipe-gestures)/)',
  ],
  setupFiles: ["../../node_modules/react-native-gesture-handler/jestSetup.js"],
};

to the file jest.config.ts

PhamQuyet1606 commented 2 months ago

Thanks @LayMui, but my issue is when the app running on the device, and I haven't run unit test yet

mckenzieja commented 2 months ago

installing

@mikey18 have you resolve this error?

i have a very similar issue too ERROR Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["PlatformConstants","LogBox","SourceCode","Timing","AppState","BlobModule","WebSocketModule","DevSettings","DevToolsSettingsManager","Networking","Appearance","DevLoadingView","HeadlessJsTaskSupport","DeviceInfo","UIManager","DeviceEventManager","RNCSafeAreaContext","NativeAnimatedModule","SoundManager","I18nManager","StatusBarManager","StatusBarManager","ImageLoader"],"TurboModules":[],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","RedBox","BugReporting","FrameRateLogger","KeyboardObserver","RNGestureHandlerModule"]}, js engine: hermes ERROR Invariant Violation: "main" has not been registered. This can happen if:

  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it, and restart it in the current project.
  • A module failed to load due to an error, and AppRegistry.registerComponent wasn't called., js engine: hermes

I am using expo development Build; i have rebuilt the app so many times, cleared my cache, and nothing works im using a windows PC. Please, has anyone faced this issue and gotten a fix?, i've been trying to debug this thig for a week now, and i'm seriously getting tired of React Native at this point, more of debugging than actual productivity.

please guide me to be resolve this?

use npm i react-native-gesture-handler Fixed it for me.

inayatAliDev commented 4 days ago

I had the same issue when running my tests. This solution (link) from React Navigation docs helped me to resolve it.

setup-jest.js

import 'react-native-gesture-handler/jestSetup';

jest.config.js

{
  "setupFiles": [
    "<rootDir>/setup-jest.js"
  ],
}

import 'react-native-gesture-handler/jestSetup';

By adding above line solved issue for me Thanks dud