react-native-localize: RNLocalize gets an undefined object on RNLocalize.initialContants
Hello !
We used react-native-languages with i18n-js in our app to easly manage the translations. Now that it has been updated and that we’ve done the migration, we faced a strange exception as described below.
Describe your environment
- react-native-localize v 1.0.1
- react-native v 0.57.7
- Target platform: both
- Device : Android Virtual Device
- OS version: Android 6.0
- DevTools: Android Studio v 3.1.4 with build tools v 27.0.3
How to repeat issue and example
Before the update to RNLocalize, everything worked fine, I did nothing more than copying the example. After the update, I followed the steps described here.
- Unlink then uninstall react-native-languages with npm
- Install then link react-native-localize
- Edited my i18n.js file to be the exact same as in the link above
react-native run-androidnow instantly throws me this exceptionundefined is not an object (evaluating 'RNLocalize.initialContants')even in the console it’s the only thing printed.
I’m not really confident with react-native and I don’t have any clue about what’s happening.
I created a new project with only react-native-localize and i18n-js installed, but I got the same result except the value was nulland not undefined.
Basically just using import * as RNLocalize from 'react-native-localize throws this exception.
Have you any clues about what could cause this issue ?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 44 (12 by maintainers)
I did have the same errors on iOS. (did not test android yet). Manual linking did work, adding the RNLocalize.xcodeproj to the libraries on the project navigator AND (missing in the docs) adding libRNLocalize.a in the linked frameworks and libraries in the general tab of the target app.
So it seems the automatic linking is not working as advertised.
@duluong This package will not works with Expo (you can’t install native packages in Expo without exjecting to Expokit). Check the Expo documentation to achieve the same effect: https://docs.expo.io/versions/v33.0.0/sdk/localization/
just link the package with project… autolink is not working for this package.
react-native link react-native-localize(root) ->
cd .\android\->.\gradlew clean->cd..->react-native run-androidI’m having the same issues with
0.60-rc1version on iOS. Android works fineI just tried using:
Without any issues. It’s probably due to
react-native link, which version ofreact-native-cliandreact-nativedo you use? Do areact-native -vin your project and give me the output please 🙂Ignore it, you’re right, I forgot to update the mock file 😃 Works for me now.
I’m experiencing the same issue, making at least our jest tests fail:
Oh my god, thank you so much for clarifying this! I’ve tried for hours to solve this unsolvable problem because I was trying to use it with my managed Expo project…
There’s a react native example called RocketChat: https://github.com/RocketChat/Rocket.Chat.ReactNative This example uses both i18n and React-Native-Localize, but they have an iOS and android folder, which means they ejected their project or something? How does this work and how could I make my expo project compatible with react-native-localize?
I’m having the same issue on Android devices. Is there a known fix? I tried both the manual configuration and
react-native link.@plahteenlahti On React Native 0.60, you have nothing more to do than
yarn add react-native localizeandpod install. Autolinking will do the rest. Check https://github.com/react-native-community/react-native-localize/tree/master/exampleI’ve upgraded my app to the latest react-native version (use
react-native-git-upgrade!), solving many issues that popped up along the way. These issues may be related to some other issue in my project that I am not aware of, but just in case someone else encounters these problems as well, I will share my experiences and the solution that worked in my case.Building on iOS requires some changing of a script that installs third-party elements (see this issue and this issue). Fix the path of
glogsin theios-install-third-party.shscript to:"\"../../$SCRIPTDIR/ios-configure-glog.sh\""(for more info see my comment)Anyway, returning to this issue: after upgrading and solving all the other issues, this error disappeared. I do not know what exactly fixed the issue, but upgrading to the latest react-native version seems to do the trick.
Sorry, how did you do that I am stuck in this error after migrating from RN 0.59.10 to 0.60.0
Sure, It is documented here on how to do it manually: https://github.com/react-native-community/react-native-localize#manual-android
can you please give an example of how you changed this?
I solved it by adding
RNLocalize.xcodeprojto Libraries manually.