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

Comments

Projects
None yet
4 participants
@vendramini
Copy link

vendramini commented Aug 5, 2017

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

newyankeecodeshop commented Aug 7, 2017

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

This comment has been minimized.

Copy link
Author

vendramini commented Aug 7, 2017

@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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.