Skip to content

Commit 941129a

Browse files
committed
fix: Fix TurboModule not found error by checking both names
I think C++ modules have been renamed to drop the `Cxx` suffix.
1 parent 4e7f7e0 commit 941129a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

package/src/ModuleNotFoundError.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { NativeModules, Platform } from 'react-native';
33
declare global {
44
// A react-native internal from TurboModuleRegistry.js
55
var __turboModuleProxy: unknown | undefined;
6+
// A react-native internal
7+
var RN$Bridgeless: unknown | undefined;
68
}
79

810
const BULLET_POINT = '\n* ';
@@ -33,7 +35,7 @@ function getFrameworkType(): 'react-native' | 'expo' | 'expo-go' {
3335
export class ModuleNotFoundError extends Error {
3436
constructor(cause?: unknown) {
3537
// TurboModule not found, something went wrong!
36-
if (global.__turboModuleProxy == null) {
38+
if (global.__turboModuleProxy == null && global.RN$Bridgeless == null) {
3739
// TurboModules are not available/new arch is not enabled.
3840
// react-native-mmkv 3.x.x requires new arch (react-native >0.74)
3941
// react-native-mmkv 2.x.x works on old arch (react-native <0.74)

package/src/NativeMmkv.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,15 @@ export function getMMKVTurboModule(): Spec {
100100
try {
101101
if (mmkvModule == null) {
102102
// 1. Load MMKV TurboModule
103-
mmkvModule = TurboModuleRegistry.getEnforcing<Spec>('MmkvCxx');
103+
mmkvModule = TurboModuleRegistry.get<Spec>('MmkvCxx');
104+
if (mmkvModule == null) {
105+
mmkvModule = TurboModuleRegistry.get<Spec>('Mmkv');
106+
}
107+
if (mmkvModule == null) {
108+
throw new Error(
109+
`Could not find the MMKV TurboModule! (Tried "MmkvCxx" and "Mmkv")`
110+
);
111+
}
104112

105113
// 2. Get the PlatformContext TurboModule as well
106114
const platformContext = getMMKVPlatformContextTurboModule();

0 commit comments

Comments
 (0)