react-native-tvos / IgniteTV

32 stars 6 forks source link

TypeError: Cannot read property 'languageTag' of undefined #1

Closed Sculas closed 8 months ago

Sculas commented 8 months ago

I've cloned the repo and followed these instructions:

yarn
export EXPO_TV=1
npx expo prebuild --clean --no-install
yarn android # no need to specify name, emulator was already running

But as soon as I run it on my Google TV emulator, this error is thrown:

 ERROR  TypeError: Cannot read property 'languageTag' of undefined, js engine: hermes
 ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes

img img

douglowder commented 8 months ago

Thanks for the report, I'll have a look

douglowder commented 8 months ago

I am not able to reproduce the issue. The error you are seeing is what you would expect if you were already running Metro from a different terminal. Is that a possibility?

Also, what API level is your TV emulator running (API 31, 33, or something newer)?

Sculas commented 8 months ago

The error you are seeing is what you would expect if you were already running Metro from a different terminal. Is that a possibility?

Hmm, that's indeed a possibility. My host machine is Windows 11 and I'm running everything but the emulator inside of WSL2 (Ubuntu, because compiling native code on Windows is hot garbage), with the emulator being started from Android Studio. I used this little trick to get this working (which it does with an unmodified Ignite project and an Android phone emulator, but not this?).

Also, what API level is your TV emulator running (API 31, 33, or something newer)?

I just checked and it's API level 30.

douglowder commented 8 months ago

Ok in looking at your i18n.ts error, it seems that there is a problem in the system locale returned by expo-localization in API 30 (I don't see this in API 31). I've pushed some changes to the main branch that should work around that issue. Please pull the main branch and try running the app again.

Sculas commented 8 months ago

That's weird! I've checked your commit, and I'm pretty sure it's still going to fail, because systemLocale is undefined, yet it's still being referenced here: https://github.com/react-native-tvos/IgniteTV/blob/2c48a8c04c801d6d2538a420b5cf2d17b342a193/app/i18n/i18n.ts#L35 Just to make sure it's just API level 30, I'll try out API level 31 and see where that brings me.

douglowder commented 8 months ago

Good catch! Change systemLocale.textDirection to systemLocale?.textDirection

Sculas commented 8 months ago

Sweet, that works! (testing on API level 30) However, localization not working on API level 30 does sound like a bug to me. Has this been reported yet?

douglowder commented 8 months ago

I don't think so -- but it may be something specific to the TV emulator you are using. It might be informative to do adb logcat and look for entries matching expo-localization, to see if any errors are being reported.

douglowder commented 8 months ago

@Sculas I've followed up with Infinite Red to address this in their boilerplate: https://github.com/infinitered/ignite/pull/2631

Sculas commented 8 months ago

Thank you for getting this fixed so fast! I'll check if I can find something in adb logcat.

Sculas commented 8 months ago

I should've done this much sooner! This is the issue:

02-09 14:28:35.669  7028  7113 W expo-localization: Failed to get locale for index 0
02-09 14:28:35.669  7028  7113 W expo-localization: java.lang.IllegalArgumentException: Unsupported ISO 3166 country: en_XC
02-09 14:28:35.669  7028  7113 W expo-localization:     at java.util.Currency.getInstance(Currency.java:371)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.localization.LocalizationModule.getPreferredLocales(LocalizationModule.kt:164)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.localization.LocalizationModule.access$getPreferredLocales(LocalizationModule.kt:31)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.localization.LocalizationModule$definition$lambda$6$$inlined$FunctionWithoutArgs$1.invoke(ObjectDefinitionBuilder.kt:407)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.localization.LocalizationModule$definition$lambda$6$$inlined$FunctionWithoutArgs$1.invoke(ObjectDefinitionBuilder.kt:97)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.kotlin.functions.SyncFunctionComponent.call(SyncFunctionComponent.kt:24)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.kotlin.functions.SyncFunctionComponent.getJNIFunctionBody$lambda$2(SyncFunctionComponent.kt:32)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.kotlin.functions.SyncFunctionComponent.$r8$lambda$ddHjggTYuq5WYMBqeQr3LIdxq-A(Unknown Source:0)
02-09 14:28:35.669  7028  7113 W expo-localization:     at expo.modules.kotlin.functions.SyncFunctionComponent$$ExternalSyntheticLambda0.invoke(Unknown Source:6)
02-09 14:28:35.669  7028  7113 W expo-localization:     at com.facebook.jni.NativeRunnable.run(Native Method)
02-09 14:28:35.669  7028  7113 W expo-localization:     at android.os.Handler.handleCallback(Handler.java:938)
02-09 14:28:35.669  7028  7113 W expo-localization:     at android.os.Handler.dispatchMessage(Handler.java:99)
02-09 14:28:35.669  7028  7113 W expo-localization:     at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
02-09 14:28:35.669  7028  7113 W expo-localization:     at android.os.Looper.loop(Looper.java:223)
02-09 14:28:35.669  7028  7113 W expo-localization:     at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:234)
02-09 14:28:35.669  7028  7113 W expo-localization:     at java.lang.Thread.run(Thread.java:923)

A quick Google search leads me here: https://android.googlesource.com/platform/build/+/android-10.0.0_r40/target/product/languages_full.mk I wonder why Android 10 emulators don't have a proper locale set...?


Edit: I was able to fix this by setting the language in the Android settings to English (US). It seems like it was set to a language it didn't even know about because none of the radio buttons were toggled (as if no language was ever selected).