Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reloading/Fast refreshing throws error: "_reactNativeMmkv.getString is not a function" #24

Closed
a-eid opened this issue Mar 9, 2021 · 26 comments · Fixed by #92
Closed
Labels
bug Something isn't working

Comments

@a-eid
Copy link

a-eid commented Mar 9, 2021

I weirdly get this error somettimes / often

context:

I check for the token right away globally in the app, could it be that MMKV is not available then ?

Screen Shot 2021-03-09 at 3 21 30 PM

@mrousavy
Copy link
Owner

mrousavy commented Mar 9, 2021

MMKV is being initialized as soon as the bridge is being set (see here), afaik that is before JS code can be executed so it shouldn't be undefined. Could you try adding a breakpoint there to see what gets executed first?

@a-eid
Copy link
Author

a-eid commented Mar 9, 2021

@mrousavy sorry, I'm not really sure how to do that, but will try and report back if I am successful.

@mrousavy
Copy link
Owner

mrousavy commented Mar 9, 2021

Just open your project (.xcworkspace) in Xcode, press Command + Shift + O, search for "Mmkv" and open the Mmkv.mm file. then scroll to the line I linked, click the line number at the left and run the app from Xcode. it will pause execution at the breakpoint.

@a-eid
Copy link
Author

a-eid commented Mar 9, 2021

@mrousavy it does hit the [MMKV initializeMMKV:nil]; line while on the native splash screen.

this log might be helpful.

[Tue Mar 09 2021 15:50:18.718]  LOG      Running "overlay/splash" with {"rootTag":31,"initialProps":{"componentId":"Component1"}}
[Tue Mar 09 2021 15:50:18.862]  WARN     Possible Unhandled Promise Rejection (id: 0):
TypeError: _reactNativeMmkv.MMKV.getString is not a function. (In '_reactNativeMmkv.MMKV.getString(TOKEN_KEY)', '_reactNativeMmkv.MMKV.getString' is undefined)
getToken@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:102145:43
_callee$@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:103078:41
tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:1444:23
invoke@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:1617:32
tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:1444:23
invoke@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:1517:30
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:1527:21
tryCallOne@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:6438:16
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:6539:27
_callTimer@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30977:17
_callImmediatesPass@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:31016:17
callImmediates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:31233:33
__callImmediates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5732:35
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5518:34
__guard@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5715:15
flushedQueue@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:5517:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

I'm not sure why it says, Possible Unhandled Promise Rejection (id: 0):.

@a-eid
Copy link
Author

a-eid commented Mar 9, 2021

please let me know if I can provide any more help.

@mrousavy
Copy link
Owner

So apparently all of this happens when Hot-Reloading, not normally when starting.

@crisfcodes
Copy link

crisfcodes commented Mar 14, 2021

I'm getting the similar error in expo app:

TypeError: _reactNativeMmkv.MMKV.getString is not a function. (In
 '_reactNativeMmkv.MMKV.getString(name)', '_reactNativeMmkv.MMKV.
getString' is undefined)

expo is supported?

@a-eid
Copy link
Author

a-eid commented Mar 15, 2021

@Cristian05 this package does not work with expo.

@mrousavy mrousavy added the bug Something isn't working label Mar 15, 2021
@mrousavy mrousavy changed the title _reactNativeMmkv.getString is not a function ? Hot reloading/Fast refreshing throws error: "_reactNativeMmkv.getString is not a function" Mar 15, 2021
@mrousavy
Copy link
Owner

mrousavy commented Mar 22, 2021

Can you check if the newest version (1.1.6) works for you? Note that it requires some additional installation steps, see INSTALL.md.

Also, if you can't import the library see this issue which includes a temporary workaround. I'll find a fix that requires no native changes at all soon 👍

@a-eid
Copy link
Author

a-eid commented Mar 27, 2021

when installing with reanimated 2, do we need to replace this ?

protected JSIModulePackage getJSIModulePackage() {
   return new ReanimatedJSIModulePackage();
}

@a-eid
Copy link
Author

a-eid commented Mar 27, 2021

also the app failed building on android

> Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
290 actionable tasks: 271 executed, 19 up-to-date
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: [2] Wrote GeneratedAppGlideModule with: [com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule, com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule]
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@react-native-picker/picker/android/src/main/java/com/reactnativecommunity/picker/ReactPickerManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@sentry/react-native/android/src/main/java/io/sentry/react/RNSentryModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/main/java/com/alsagheer/AlsagheerJSIPackage.java:5: error: package com.reactnativemmkv does not exist
import com.reactnativemmkv.MmkvModule;
                          ^
/Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/main/java/com/alsagheer/MainApplication.java:44: error: cannot find symbol
            return new AlsagheerJSIPackage();
                       ^
  symbol: class AlsagheerJSIPackage
/Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/main/java/com/alsagheer/AlsagheerJSIPackage.java:16: error: cannot find symbol
        MmkvModule.install(jsContext, reactApplicationContext.getFilesDir().getAbsolutePath() + "/mmkv");
        ^
  symbol:   variable MmkvModule
  location: class AlsagheerJSIPackage
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/debug/java/com/alsagheer/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@react-native-community/async-storage/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: [2] Wrote GeneratedAppGlideModule with: [com.bumptech.glide.integration.okhttp3.OkHttpLibraryGlideModule, com.dylanvann.fastimage.FastImageOkHttpProgressGlideModule]
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationUtils.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@react-native-picker/picker/android/src/main/java/com/reactnativecommunity/picker/ReactPickerManager.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@sentry/react-native/android/src/main/java/io/sentry/react/RNSentryModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/main/java/com/alsagheer/AlsagheerJSIPackage.java:5: error: package com.reactnativemmkv does not exist
import com.reactnativemmkv.MmkvModule;
                          ^
/Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/main/java/com/alsagheer/MainApplication.java:44: error: cannot find symbol
            return new AlsagheerJSIPackage();
                       ^
  symbol: class AlsagheerJSIPackage
/Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/main/java/com/alsagheer/AlsagheerJSIPackage.java:16: error: cannot find symbol
        MmkvModule.install(jsContext, reactApplicationContext.getFilesDir().getAbsolutePath() + "/mmkv");
        ^
  symbol:   variable MmkvModule
  location: class AlsagheerJSIPackage
Note: /Users/ahmedeid/zeal/alsagheer-app-reactnative/android/app/src/debug/java/com/alsagheer/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s

    at makeError (/Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/execa/index.js:174:9)
    at /Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async runOnAllDevices (/Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
    at async Command.handleAction (/Users/ahmedeid/zeal/alsagheer-app-reactnative/node_modules/@react-native-community/cli/build/index.js:186:9)
info Run CLI with --verbose flag for more details.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@a-eid
Copy link
Author

a-eid commented Mar 27, 2021

Screen Shot 2021-03-27 at 5 46 12 AM

@mrousavy
Copy link
Owner

On which MMKV version are you? You need 1.1.6

@a-eid
Copy link
Author

a-eid commented Mar 27, 2021

@mrousavy ^1.1.6 yes.

@alexreyes
Copy link

alexreyes commented Apr 1, 2021

Can also confirm that the latest version doesn't work with Expo. If this library got Expo support it would be amazing

@a-eid
Copy link
Author

a-eid commented Apr 1, 2021

@alexreyes the library is not supported by expo.

@mrousavy mrousavy closed this as completed Apr 6, 2021
@yelnar
Copy link

yelnar commented Apr 28, 2021

@a-eid did you find how to resolve your issue somehow?

@etomarat
Copy link

I have same issue! How to resolve this?

@jesseproudman
Copy link

It should be noted, this will also appear when using Codepush from Microsoft App Center.

@mrousavy
Copy link
Owner

@jesseproudman could you elaborate? I am using CodePush and MMKV works fine for me.

@jesseproudman
Copy link

jesseproudman commented Jun 28, 2021

@mrousavy Absolutely.

We've got a React-Native 0.64 app deployed via Test Flight, integrated with Appcenter / Codepush.

We're seeing frequent exceptions being raised on app boot:

TypeError: f.MMKV.getString is not a function. (In 'f.MMKV.getString("veriff-status")', 'f.MMKV.getString' is undefined)

Many of these seem to be post a Codepush update which I would assume triggers hot reloading. Many of them also just appear on first boot based on the time stamps in the logs:

08:29:47 / Running "app" with {"rootTag":1,"initialProps":{}}
08:29:47 / [CodePush] Checking for update.
08:29:47 / TypeError: t.MMKV.getString is not a function. (In 't.MMKV.getString("user-email")', 't.MMKV.getString' is undefined)

Would be super interested if you have any ideas on how to debug given yours is working. :)

@sauldom102
Copy link

sauldom102 commented Jun 30, 2021

@mrousavy I'm running into the same problem as @jesseproudman, we're not using Expo, just react-native-unimodules, it's really annoying having these random crashes, probably as you said it's due to some race condition, any help would be appreciated, thanks in advance!

@mrousavy
Copy link
Owner

mrousavy commented Jul 6, 2021

could anyone test if the changes in #92 fix this issue?

@jesseproudman
Copy link

@mrousavy giving this a go. thanks!

@jesseproudman
Copy link

This appears to have solved our issues. Will know more over the coming days.

@jesseproudman
Copy link

Just wanted to close the loop - We have not seen this particular error occur in production with this patch active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants