react-native-mmkv: [Expo Dev Client] - Failed to create new MMKV instance. The native initializer function does not exist
Getting this weird error once I press R in the terminal or with reload in my Expo dev client app:
expo start --dev-client
This error is getting spammed over 26 times. It only happens when I reload. If I restart the expo terminal it all works just fine as usual. Its very on and off when this works and when it doesn’t. I’ve tried starting the terminal with --clear
to remove bundler cache and the error persists.
- Production mode: ✅
- Dev mode first load: ✅
- Dev mode hot reload: ✅
- Dev mode reload by keydown
R
in terminal: ❌ - Dev mode reload by
Reload
button in dev client app: ❌
The hook triggering this error is this:
export const stateKeys = {
onboarded: "app.onboarded",
};
export const useOnboarded = () => useMMKVBoolean(stateKeys.onboarded);
ERROR Error: Failed to create a new MMKV instance, the native initializer function does not exist. Are you trying to use MMKV from different JS Runtimes?
This error is located at:
in AuthLayout
in Unknown (created by Route((auth)))
in Route (created by Route((auth)))
in Route((auth)) (created by SceneView)
in StaticContainer
in EnsureSingleNavigator (created by SceneView)
in SceneView (created by QualifiedSlot)
in QualifiedSlot (created by DefaultNavigator)
in PreventRemoveProvider (created by NavigationContent)
in NavigationContent
in Unknown (created by QualifiedNavigator)
in QualifiedNavigator (created by Navigator)
in Navigator (created by DefaultNavigator)
in RNCSafeAreaView
in Unknown (created by DefaultNavigator)
in DefaultNavigator
in Unknown (created by Route())
in Route (created by Route())
in Route() (created by ContextNavigator)
in RNCSafeAreaProvider (created by SafeAreaProvider)
in SafeAreaProvider (created by wrapper)
in RCTView (created by View)
in View (created by GestureHandlerRootView)
in GestureHandlerRootView (created by GestureHandlerRootView)
in GestureHandlerRootView (created by wrapper)
in wrapper (created by ContextNavigator)
in EnsureSingleNavigator
in BaseNavigationContainer
in ThemeProvider
in NavigationContainerInner (created by ContextNavigator)
in ContextNavigator (created by ExpoRoot)
in ExpoRoot (created by App)
in App (created by withDevTools(App))
in withDevTools(App) (created by ErrorOverlay)
in ErrorToastContainer (created by ErrorOverlay)
in ErrorOverlay
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent), js engine: hermes
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 8
- Comments: 37 (9 by maintainers)
Fixed in 2.11.0! ❤️💪
@nhuesmann @fli @stevengoldberg @soyjuanmacias @jake-ruth @ludwig-pro @steinalex @sannajammeh
I’m going to spend some time and fix this. Could you guys give me all your app dependencies, i want to find the common dominator. I believe it might be a package clearing the global namespace.
Guys, after struggling a bit with this problem, I found another lib that uses the MMKV from tencent: https://github.com/ammarahm-ed/react-native-mmkv-storage its working just fine in expo 49 and expo router
That was fast!! @chrispader @mrousavy thank you! ❤️
This PR fixes the problem 🚀
I’m having the same issue. Expo SDK 49, dev client build
I’m also getting this error after updating to expo SDK 49. I’m not passing a config object to MMKV, just doing
const storage = new MMKV()
.same here: “dependencies”: { “@apollo/client”: “^3.8.6”, “@gorhom/bottom-sheet”: “^4.5.1”, “@hookform/resolvers”: “^3.3.2”, “@react-native-community/blur”: “^4.3.2”, “@shopify/flash-list”: “1.4.3”, “@supabase/supabase-js”: “^2.38.2”, “apollo3-cache-persist”: “^0.14.1”, “date-fns”: “^2.30.0”, “expo”: “^49.0.16”, “expo-clipboard”: “~4.3.1”, “expo-constants”: “~14.4.2”, “expo-crypto”: “~12.4.1”, “expo-dev-client”: “~2.4.11”, “expo-gradle-ext-vars”: “^0.1.2”, “expo-image”: “~1.3.4”, “expo-linking”: “~5.0.2”, “expo-location”: “~16.1.0”, “expo-notifications”: “~0.20.1”, “expo-router”: “^2.0.0”, “expo-splash-screen”: “~0.20.5”, “expo-status-bar”: “~1.6.0”, “geodesy”: “^2.4.0”, “graphql”: “^16.8.1”, “lodash.debounce”: “^4.0.8”, “lottie-react-native”: “5.1.6”, “mobx”: “^6.10.2”, “mobx-react-lite”: “^4.0.5”, “mobx-state-tree”: “^5.2.0”, “qs”: “^6.11.2”, “radash”: “^11.0.0”, “react”: “18.2.0”, “react-hook-form”: “^7.47.0”, “react-native”: “0.72.6”, “react-native-date-picker”: “^4.3.3”, “react-native-flash-message”: “^0.4.2”, “react-native-gesture-handler”: “~2.12.0”, “react-native-maps”: “1.7.1”, “react-native-mask-input”: “^1.2.3”, “react-native-mmkv”: “^2.10.2”, “react-native-pager-view”: “6.2.0”, “react-native-paper”: “^5.11.0”, “react-native-reanimated”: “~3.3.0”, “react-native-safe-area-context”: “4.6.3”, “react-native-screens”: “~3.22.0”, “react-native-shadow-2”: “^7.0.8”, “react-native-size-matters”: “^0.4.2”, “react-native-svg”: “13.9.0”, “react-native-tab-view”: “^3.5.2”, “react-native-url-polyfill”: “^2.0.0”, “react-use”: “^17.4.0”, “responsive-native”: “^1.0.2”, “styled-components”: “^6.1.0”, “ts-pattern”: “^5.0.5”, “zod”: “^3.22.4” }, “devDependencies”: { “@babel/core”: “^7.20.0”, “@graphql-codegen/cli”: “^5.0.0”, “@graphql-codegen/client-preset”: “^4.1.0”, “@styled/typescript-styled-plugin”: “^1.0.0”, “@types/lodash.debounce”: “^4.0.8”, “@types/react”: “^18.2.31”, “typeorm”: “^0.3.17”, “typescript”: “^5.2.2” }
Happens when reload with R in terminal.
This may have something to do with Expo or something else clearing the global namespace. I changed it to be
__mmkvCreateNewInstance
instead ofmmkvCreateNewInstance
and I haven’t seen the error message in half a day. Still not 100% sure though, happy to open a PR once it’s confirmed.Have attached my .patch if you wanna give it a try with
patch-package
.react-native-mmkv+2.10.2.patch
same problem, without config
I confirm the context provide by @sannajammeh :
Those who have problem in that just remove path from it and it works.
@chrispader Thank you so much for fixing this issue!
it was fast, really nice.
thanks for your help guys!
Ok thanks, i can reproduce this now. Seems this error doesn’t occur in iOS simulators. I also get it on Android.
Will let you guys know once this is fixed 👍
iOS, monorepo setup, not consistent some reloads nothing, other times i would get the error and would have to do a complete restart of the app.
iOS here too. Ill share my deps later today
Thanks!
@chrispader, I was having the problem with these dependencies: “dependencies”: { “@apollo/client”: “^3.8.6”, “@gorhom/bottom-sheet”: “^4.5.1”, “@hookform/resolvers”: “^3.3.2”, “@react-native-community/blur”: “^4.3.2”, “@shopify/flash-list”: “1.4.3”, “@supabase/supabase-js”: “^2.38.2”, “apollo3-cache-persist”: “^0.14.1”, “date-fns”: “^2.30.0”, “expo”: “^49.0.16”, “expo-clipboard”: “~4.3.1”, “expo-constants”: “~14.4.2”, “expo-crypto”: “~12.4.1”, “expo-dev-client”: “~2.4.11”, “expo-gradle-ext-vars”: “^0.1.2”, “expo-image”: “~1.3.4”, “expo-linking”: “~5.0.2”, “expo-location”: “~16.1.0”, “expo-notifications”: “~0.20.1”, “expo-router”: “^2.0.0”, “expo-splash-screen”: “~0.20.5”, “expo-status-bar”: “~1.6.0”, “geodesy”: “^2.4.0”, “graphql”: “^16.8.1”, “lodash.debounce”: “^4.0.8”, “lottie-react-native”: “5.1.6”, “mobx”: “^6.10.2”, “mobx-react-lite”: “^4.0.5”, “mobx-state-tree”: “^5.2.0”, “qs”: “^6.11.2”, “radash”: “^11.0.0”, “react”: “18.2.0”, “react-hook-form”: “^7.47.0”, “react-native”: “0.72.6”, “react-native-date-picker”: “^4.3.3”, “react-native-flash-message”: “^0.4.2”, “react-native-gesture-handler”: “~2.12.0”, “react-native-maps”: “1.7.1”, “react-native-mask-input”: “^1.2.3”, “react-native-mmkv”: “^2.10.2”, “react-native-pager-view”: “6.2.0”, “react-native-paper”: “^5.11.0”, “react-native-reanimated”: “~3.3.0”, “react-native-safe-area-context”: “4.6.3”, “react-native-screens”: “~3.22.0”, “react-native-shadow-2”: “^7.0.8”, “react-native-size-matters”: “^0.4.2”, “react-native-svg”: “13.9.0”, “react-native-tab-view”: “^3.5.2”, “react-native-url-polyfill”: “^2.0.0”, “react-use”: “^17.4.0”, “responsive-native”: “^1.0.2”, “styled-components”: “^6.1.0”, “ts-pattern”: “^5.0.5”, “zod”: “^3.22.4” }, “devDependencies”: { “@babel/core”: “^7.20.0”, “@graphql-codegen/cli”: “^5.0.0”, “@graphql-codegen/client-preset”: “^4.1.0”, “@styled/typescript-styled-plugin”: “^1.0.0”, “@types/lodash.debounce”: “^4.0.8”, “@types/react”: “^18.2.31”, “typeorm”: “^0.3.17”, “typescript”: “^5.2.2” }
The thing is that the problem is not 100% of times consistent, had times that I reloaded and it didnt failed.
Is anyone experiencing this in a clean expo project? In my case, Im using managed workflow with dev client, so I install the dependencies above and run expo prebuild. My expo plugins:
Im in a monorepo using expo router, I think that the problem is related to expo router, your fresh test used expo router?
which platform are you experiencing this issue? iOS and/or Android? in my case, iOS
Yeah, we have also switched to this library instead now. I tried finding the issue but just couldn’t.
We are still encountering this issue, any possible solutions?
@claudesortwell
Hey!