Luxon: React Native (Android) can't find variable Intl

Created on 1 Nov 2017  路  10Comments  路  Source: moment/luxon

screen shot 2017-11-01 at 21 14 46
Is it possible to use this library in React Native? I'm getting this error on Android.
Thanks
code causing problem is below:

````
const clockInDate = DateTime.fromMillis(shift.clockIn).toLocaleString({
day: "numeric",
month: "short",
weekday: "short"
});

const clockOutDate = shift.clockOut
? DateTime.fromMillis(shift.clockOut).toLocaleString({
day: "numeric",
month: "short",
weekday: "short"
})
: "-";
````

Edit:
I've found this can be fixed by using this library which seems excellent:
https://github.com/SoftwareMansion/jsc-android-buildscripts

Most helpful comment

I have the same error. is there a solution?

All 10 comments

Yikes. A few thoughts:

  1. I'm glad you found a solution. I will add it to the documentation.
  2. I've been slowly fixing places where the absence of Intl breaks things. I currently do expect toLocaleString to not break without Intl. See this doc for the caveats. Basically, you might not get exactly the strings you expect but it shouldn't have thrown either. I'll look into it. Are you sure you were on the latest version of Luxon? I have been pretty actively fixing this stuff and there are some (not terribly thorough) tests for it.
  3. I would like to support React Native but I don't know much about it. It surprises me that it doesn't provide Intl.

hmm I was on version 0.0.10. I'll try taking the build scripts out and trying again with 0.0.12, however I imagine the need for those scripts is real given they exist at all

I'm just basing this on what they say: "An obvious benefit for everyone using React Native is that this will allow us to update JSC for React Native on Android much more often than before (note that facebook/android-jsc uses JSC version from Nov 2014), which is especially helpful since React Native on iOS uses the built-in copy of JSC that is updated with each major iOS release")

I will say that I had been using moment.format() earlier and it was causing some really strange and inconsistent results on our android version, so I'm wondering if that is related to the need for this

Also if you're not familiar with RN, Expo.io are a great organization that basically provide a simple way of configuring and deploying react native apps, so they are highly respectable and I can imagine that solution would be a very good one.
And thanks for the library!

Right, it looks like the RN environment is missing the Intl API but that library provides it. And to get the full features of Luxon you definitely need that. What I'm saying is that Luxon should at least not break so horribly and I'd be surprised if it the latest version did. But I could be wrong!

Well honestly given that we seem to have a working solution ^, I think it's better as long as it's documented. Because using it without that library could lead to very strange unpredictable results, so in a way I feel it's maybe better to just have it break (which means the user takes immediate action), fix it, and have it work reliably.
There are ways to customise the 'red box error' shown in react native to communicate things but I think it falls a bit outside the scope of this library. For now I think maybe this issue and the documentation should be ok?
Personally I think the idea of it failing silently might be worse in the long run because the real problems won't manifest themselves until developers with apps in production start hearing reports of strange behavior back from their users

I added some docs

Great thanks. Amazingly I still don't really know how to create a pull request (I know I know...)
But I made this gist to give a bit of an overview and point out that it only is a problem on Android
https://gist.github.com/SamMatthewsIsACommonName/906dcbfdb1d3582948d4878bc2790aff

Loudly failing makes sense for RN, but it's really painful in browsers, where the browser the developer is using is not the same one their users use. Anyway, I did track the root issue down and fix it.

I've also updated the documents to clarify that the build script thing is only needed for Android.

Of course, I didn't even think of that! Thanks

The weird thing is, it's working for me in development mode on Android without any error, but as soon as I go into production mode, it doesn't work anymore. I'll try the solution mentioned above though...

I have the same error. is there a solution?

Was this page helpful?
0 / 5 - 0 ratings