sayem314 / react-native-keep-awake

Keep the screen from going to sleep. iOS and Android.
MIT License
205 stars 29 forks source link

'ReactNativeKCKeepAwake' could not be found. Verify that a module by this name is registered in the native binary. #11

Open raduvarga opened 7 months ago

raduvarga commented 7 months ago

I am getting the above error after installing the library. On iOS, I figured I have to install the pods and then the error went away. Are there further Android installation instructions?

aybarska commented 7 months ago

Same here. Cant run on android.

sayem314 commented 7 months ago

We have a app running with older builds, I haven't touched react-native in a while so I cannot debug this atm.

SpaceTimeEvent commented 6 months ago

Same on iOS latest RN

owlfrancesco commented 6 months ago

I am getting a similar error, but only when running tests with jest:

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'ReactNativeKCKeepAwake' could not be found. Verify that a module by this name is registered in the native binary.

Version 1.2.3

Any ideas?

rebeccachin commented 5 months ago

Hey @owlfrancesco, I also encounter the same.

I solved it by adding a mock for TurboModuleRegistry.getEnforcing(...), as per this stackoverflow thread

jest.mock('react-native/Libraries/TurboModule/TurboModuleRegistry', () => {
  const turboModuleRegistry = jest.requireActual('react-native/Libraries/TurboModule/TurboModuleRegistry');
  return {
    ...turboModuleRegistry,
    getEnforcing: (name) => {
      // List of TurboModules libraries to mock.
      const modulesToMock = ['ReactNativeKCKeepAwake'];
      if (modulesToMock.includes(name)) {
        return null;
      }
      return turboModuleRegistry.getEnforcing(name);
    },
  };
});