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

Tried to access a JS module before the React instance was fully set up #44

Closed
Boubaker93 opened this issue Mar 27, 2019 · 2 comments
Closed

Comments

@Boubaker93
Copy link

Describe your environment

  • react-native-localize version 1.1.0
  • react-native version 0.58.6
  • Target platform: Android
  • Device Samsung Galaxy S6
  • OS version Android 8.0
  • DevTools: Xcode version 1.32.3 Android Studio version 3.1.4
  • Android only: buildToolsVersion 28.0.3

How to repeat issue and example

Honestly, I dont know how exactly to repeat this issue since it happened in my production app and not in my test devices. But this is the stacktrace that i got from crashlytics maybe it can help solve the problem :

Caused by java.lang.RuntimeException: Tried to access a JS module before the React instance was fully set up. Calls to ReactContext#getJSModule should only happen once initialize() has been called on your native module.
       at com.facebook.react.bridge.ReactContext.getJSModule(ReactContext.java:98)
       at com.reactcommunity.rnlocalize.RNLocalizeModule.emitLocalizationDidChange(RNLocalizeModule.java:115)
       at com.reactcommunity.rnlocalize.RNLocalizeModule.onLocalizationDidChange(RNLocalizeModule.java:91)
       at com.reactcommunity.rnlocalize.RNLocalizeModule.access$000(RNLocalizeModule.java:35)
       at com.reactcommunity.rnlocalize.RNLocalizeModule$1.onReceive(RNLocalizeModule.java:59)
       at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52226(LoadedApk.java:1319)
       at android.app.-$Lambda$FilBqgnXJrN9Mgyks1XHeAxzSTk.$m$0(-.java:4)
       at android.app.-$Lambda$FilBqgnXJrN9Mgyks1XHeAxzSTk.run(-.java)
       at android.os.Handler.handleCallback(Handler.java:789)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6944)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

And here is the only peace of code that i'm using that calls this library :

import { I18nManager } from "react-native";
import memoize from "lodash.memoize";
import i18n from "i18n-js";
import * as RNLocalize from "react-native-localize";
import en from './locales/en';
import fr from './locales/fr';

export const translate = memoize(
  (key, config) => i18n.t(key, config),
  (key, config) => (config ? key + JSON.stringify(config) : key),
);

export const getBestAvailableLanguage = memoize((locals) => {
  const bestAvailableLanguage = RNLocalize.findBestAvailableLanguage(Object.keys(locals))
  if (bestAvailableLanguage && bestAvailableLanguage.languageTag) {
    return bestAvailableLanguage.languageTag
  }
  return 'en'
});

translate.cache.clear();
getBestAvailableLanguage.cache.clear();

const fallback = { languageTag: "en", isRTL: false };

const { languageTag, isRTL } =
  RNLocalize.findBestAvailableLanguage(['en', 'fr']) || fallback;

I18nManager.forceRTL(isRTL);

i18n.missingBehaviour='guess';
i18n.locale = languageTag;
i18n.translations = {
  fr,
  en
};

Thank you for your help.

Solution

None

@zoontek
Copy link
Owner

zoontek commented Mar 30, 2019

Hello @Boubaker93,

I might have found a solution, it needs more tests to reproduce the error.

Edit: Just published v1.1.1, it should be fixed!

@Boubaker93
Copy link
Author

@zoontek
Nice Thanks dude 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants