ReferenceError: Intl is not defined in Node.js

internationalization, javascript, node.js

Solution

Unfortunately node currently (as of version 0.10, at time of writing) does not support the ECMA-402 `Intl` object unless you perform a custom compile of node, which is documented in the node.js Readme.

With libicu i18n support:

svn checkout --force --revision 214189 \
   http://src.chromium.org/svn/trunk/deps/third_party/icu46 \
   deps/v8/third_party/icu46
./configure --with-icu-path=deps/v8/third_party/icu46/icu.gyp
make

make install

If compiling a custom build of node is not an option or the idea fills you with dread, a workaround is to use the intl module, a Javascript polyfill which covers much of the EMCA-402 standard, except for the `Intl.Collator`, the reasons for which are covered in the project Readme file.

Using the module is straight-forward:

npm install intl --save

Then in your node code:

var Intl = require('intl');
console.log(new Intl.NumberFormat("de-DE").format(12345678));

Hope this helps.

Problem

I'm trying to construct a `new Intl.Collator()` object in Node.js. Does anyone know why the `Intl` object wouldn't be present in a Node runtime? According to MDN, it is specified as a Namespace by ECMAScript, so I don't see why it wouldn't be there.

Original source