-->

“Intl not available” in Edge 15

2020-08-17 12:19发布

问题:

I'm seeing an Intl not available error in the JS console when my script runs the following code in Edge 15:

new Date().toLocaleDateString()

I'm a bit stumped by this. It is working just fine in Edge 14, and I can't find any reference to the internationalization API suddenly disappearing from Edge 15.

I'm not sure if this is the proper way to test it, but running window.hasOwnProperty("Intl") in the console actually returns true. To me this seems to indicate that Intl actually is there.

Anyone with more JS skills able to tell what is really going on here?

回答1:

Make sure your JS code doesn't redefine standard Map class.

We had almost the same problem, but with Intl.Collator object instead. We couldn't use String.prototype.localeCompare("...", "locale") because of this.

You can look at this codepen in Edge 15 and in other browsers for explanation: https://codepen.io/kgorob/pen/pweaWV.

P.S. I'm not sure your problem is because of Map class specifically, maybe it's some other standard JS class you are re-defining.



回答2:

The problem is because of these lines in Chakracore code. Intl.js is javascript file that is used internally to perform various internationalization specific operations. Since Mapis used, over-writing it before Intl.js code executes (it is executed lazily), causes problem. This should be addressed soon.



回答3:

As ksp's answer says, this is caused by Intl lazy-loading after Map is overwritten. Therefore, the easiest workaround is to just force it to initialise early, before other scripts run:

<html>
  <head>
  <script>Intl.DateTimeFormat</script>
  ...

Here is the issue in the Chakra repo: https://github.com/Microsoft/ChakraCore/issues/3189