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

Can't use Intl.NumberFormat without Debug JS Remotely turned on #15382

Closed
vendramini opened this issue Aug 5, 2017 · 3 comments
Closed

Can't use Intl.NumberFormat without Debug JS Remotely turned on #15382

vendramini opened this issue Aug 5, 2017 · 3 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@vendramini
Copy link

Is this a bug report?

I think so.

Have you read the Contributing Guidelines?

Yes.

Environment

  1. react-native -v: 0.46.4, cli: 2.0.1
  2. node -v: 8.2.1
  3. npm -v: 5.3.0

Then, specify:

  • Target Platform: Both, but I just tested on Android for now.
  • Development Operating System: Linux Mint 17
  • Build tools: I use JetBrains PHPStorm to code. Build with default react-native run-*

Steps to Reproduce

(Write your steps here:)

  1. Try to use a simple code:
export const formatReal = (value) => {
    const formatter = new Intl.NumberFormat('pt-BR', {
        style: 'currency',
        currency: 'BRL',
        minimumFractionDigits: 2,
    });

    return formatter.format(value);
}
  1. Works if the debugger is conected.
  2. Turn off debugger from device.
  3. Explodes an error: "Can't find variable: Intl".
@hey99xx
Copy link

hey99xx commented Aug 6, 2017

It's very possible that Chrome has Intl defined, but Android JSC engine which is closer to iOS 8's JSC engine doesn't. This is not a bug with react-native; you'll always see newer JS variables / functions while working with a debugger that what ships with your app. For example localeCompare would also behave differently according to #12597

You'll need to polyfill Intl on Android with a package such as https://github.com/andyearnshaw/Intl.js/

@newyankeecodeshop
Copy link
Contributor

You can also use SoftwareMansion's work which brings an updated JavaScriptCore to Android:
https://github.com/SoftwareMansion/jsc-android-buildscripts

The version roughly matches the JavaScriptCore bundled with iOS 10.3, so it has many of the modern JavaScript APIs, including Intl. Note that there is a special build that includes the full locale stack. I've started using this in a React Native project, and it works very well.

@vendramini
Copy link
Author

@newyankeecodeshop very interesting, I will use this on future apps.

I solved using @hey99xx solution. I'm just importing intl and specifics locales.

Thank you, guys!

@facebook facebook locked as resolved and limited conversation to collaborators Aug 7, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Aug 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants