Aaron Presley

Multiple Node Versions With Full ICU April 17, 2018 Topics: i18n

I have a few different projects that all rely on a different version of node. In a perfect world, I'd be able to use the Node Version Manager. However, currently the nvm command breaks when passing the --with-intl=full-icu argument (see GitHub Issue here).

What I have to do instead, is build multiple versions of node from source, and manually switch. Here's how I'm doing it on my Mac Sierra 10.12.6.

First, add the following to your ~/.bashrc file:

export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

Now I create a directory that will hold all of my versions of node in one place

mkdir ~/.node-versions

Then clone the node repo at your desired tag, I'm using v6.7.0

git clone --branch v6.7.0 https://github.com/nodejs/node.git ~/.node-versions/v6.7.0

Change to your new directory, then set the configuration to download Full ICU:

./configure --with-intl=full-icu --download=all

Now build the source, using 7 concurrent threads (this will take a bit)

make -j7

After that runs, you'll need to make a symlink to your new node install as well as npm

ln -s ~/.node-versions/v6.7.0/node /usr/local/bin && ln -s ~/.node-versions/v6.7.0/deps/npm/bin/npm-cli.js /usr/local/bin/npm

Now you should see your desired version from the node command

$ node --version

And to ensure that Full ICU message worked, you can do the following

$ node
> new Intl.DateTimeFormat('es',{month:'long'}).format(new Date(9E8));

If you see 'January' instead of 'enero', that means it didn't work :(

Update: I wrote a quick python script to make it easier for me to switch versions back and forth. You can see it here.