6

I am developing an app with React Native to run on IOS and Android. I use Intl.numberformat() to print currency, and it works smoothly when the app runs on IOS, but I get this error when running on Android: ReferenceError: Can't find variable: Intl.

How can I make it run in both plataforms?

HuLu ViCa
  • 5,077
  • 10
  • 43
  • 93

1 Answers1

11

I had faced similar issue. The issue was with Javascript core which runs the react- native. There are two ways to overcome this.

1.Method 1 You'll have to integrate latest javascript core into your android build or upgrade react native to 0.59

You can find it here

  1. Method 2 Add or override the following code in your app/build.gradle

def jscFlavor = 'org.webkit:android-jsc-intl:+'

Clean build and react-native run android

Akshay Shenoy
  • 1,194
  • 8
  • 10
  • Only method 2 worked for me. Using RN 0.66 – Frank Fu Nov 14 '21 at 07:24
  • 1
    How could we fix this if the app is using Expo? – Esteban Chornet Feb 10 '22 at 10:55
  • @EstebanChornet Did you find any solution for Expo? – Fred A Feb 26 '22 at 00:12
  • 3
    Installing the intl package solved the issue for me for expo building on android https://www.npmjs.com/package/intl – Esteban Chornet Mar 01 '22 at 09:00
  • 1
    I installed `Intl@1.2.5` with `react-native@0.64.x` and it doesn't work for me for some regions like pt-BR on Android. NumberFormat returns a number in the imperial format while it should be metric. On iOS it works though. – Caio Mar May 12 '22 at 20:58
  • My problem was that the library `Intl` wasn't formatting my numbers correctly for specific regions, All I had to do was to import every locale considered in the beginning of the file like: `import "intl/locale-data/jsonp/pt-BR"` and it worked. With extra steps you can import it dynamically, which then I did, probably better. – Caio Mar May 12 '22 at 22:36
  • @EstebanChornet you should place your comment as a full answer to the question. – aminator Dec 16 '22 at 13:52