mrousavy / react-native-mmkv

⚡️ The fastest key/value storage for React Native. ~30x faster than AsyncStorage!
https://mrousavy.com
MIT License
6.2k stars 259 forks source link

Reloading expo app throws Error: Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules #733

Closed davidchieregato closed 2 months ago

davidchieregato commented 2 months ago

I am using Expo 51 with react-native 0.75.2 and react-native-mmkv 3.0.2

Only after the app reload pressing 'r' the below error appears, but the new architecture is clearly enabled

› Logs for your project will appear below. Press Ctrl+C to exit.
iOS Bundled 3940ms node_modules/expo-router/entry.js (1238 modules)
[micarenewapp] [RNMMKV]: Initializing MMKV at
/Users/David_Chieregato/Library/Developer/CoreSimulator/Devices/3D08537D-7C9C-451B-B129-0759E669A147/data/Containers/Data/Application/78861F6A-A8CD-40E1-94CC-5D1BC57D70A3/Documents/mmkv...
[micarenewapp] [RNMMKV]: Creating MMKV instance "mmkv.default"... (Path: , Encrypted: false)
 (NOBRIDGE) LOG  Bridgeless mode is enabled
› Reloading apps
[micarenewapp] [RNMMKV]: Destroying MMKV instance "mmkv.default"...
iOS Bundled 54ms node_modules/expo-router/entry.js (1 module)
iOS Bundled 51ms node_modules/expo-router/entry.js (1 module)
[micarenewapp] [RNMMKV]: Initializing MMKV at
/Users/David_Chieregato/Library/Developer/CoreSimulator/Devices/3D08537D-7C9C-451B-B129-0759E669A147/data/Containers/Data/Application/78861F6A-A8CD-40E1-94CC-5D1BC57D70A3/Documents/mmkv...
[micarenewapp] [RNMMKV]: Creating MMKV instance "mmkv.default"... (Path: , Encrypted: false)
 (NOBRIDGE) LOG  Bridgeless mode is enabled
 ERROR  Warning: Error: Failed to create a new MMKV instance: react-native-mmkv 3.x.x requires TurboModules, but the new architecture is not enabled!
* Downgrade to react-native-mmkv 2.x.x if you want to stay on the old architecture.
* Enable the new architecture in your app to use react-native-mmkv 3.x.x. (See https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md), js engine: hermes 
    at ContextNavigator (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:173256:24)
    at ExpoRoot (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:173228:28)
    at App
    at ErrorToastContainer (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:195061:24)
    at ErrorOverlay
    at withDevTools(ErrorOverlay) (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:191290:27)
    at RCTView
    at View (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:62656:43)
    at CssInterop.View (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:11073:45)
    at RCTView
    at View (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:62656:43)
    at CssInterop.View (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:11073:45)
    at AppContainer (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:81038:25)
    at main(RootComponent) (http://xx.xx.xx.xx:8081/node_modules/expo-router/entry.bundle//&platform=ios&dev=true&hot=false&lazy=true&transform.engine=hermes&transform.bytecode=true&transform.routerRoot=app:92535:28)
maintenance-hans[bot] commented 2 months ago

Guten Tag, Hans here! 🍻 It looks like you are having trouble with react-native-mmkv related to TurboModules.

You mentioned that the new architecture is enabled, but ze error states it is not. Could you please double-check your settings to ensure TurboModules are indeed enabled in your configuration?

Also, please provide logs from Xcode or adb logcat when you encounter this error after the reload. These logs are crucial for diagnosing ze issue properly.

If you need help with enabling TurboModules, check the documentation here.

Remember, if you want faster responses and support, consider sponsoring mrousavy's work on this project: sponsor here.

Thanks!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

amutsch commented 2 months ago

Hi @davidchieregato

It does not look like you have new architecture enabled. Bridgeless mode comes from the switch from yoga to Yoga 3 in RN 74. New architecture still requires toggling a change in your gradle.properties and a little more to enable it in IOS and the log message will then indicate fabric being enabled which I don't see.

Thanks

davidchieregato commented 2 months ago

So this is interesting,

In my app.json I have newArchEnabled

"plugins": [
      [
        "expo-build-properties",
        {
          "ios": {
            "newArchEnabled": true
          },
          "android": {
            "newArchEnabled": true
          }
        }
      ]
    ]

I just checked also the android gradle.properties which includes newArchEnabled=true

But the log still shows

 (NOBRIDGE) LOG  Bridgeless mode is enabled

Both on iOS and android. So probably the problem is not in this library as my logs are not showing "fabric": true. Not sure what the issue may be.

amutsch commented 2 months ago

I'll have to see if I have time to update mmkv and react native to see what is going on, I'll try and get back to you this week.

mrousavy commented 2 months ago

Does it work if you delete those two lines? https://github.com/mrousavy/react-native-mmkv/blob/12c051704e0db363f9f63d2b30dbf291151f90d4/package/cpp/MmkvHostObject.cpp#L56-L57

mrousavy commented 2 months ago

(NOBRIDGE) LOG Bridgeless mode is enabled

This means you are on new arch, so it should be fine.

davidchieregato commented 2 months ago

It seems that deleting the android and ios folders fixed the issue today, probably it was not related to the library. Closing this.

victorpavlenko commented 1 month ago

Same issue for my android build.

"plugins": [
      [
        "expo-build-properties",
        {
          "ios": {
            "newArchEnabled": true
          },
          "android": {
            "newArchEnabled": true
          }
        }
      ]
]

Same

(NOBRIDGE) LOG Bridgeless mode is enabled

But in my case prebuild clear doesnt help