Using Yarn with Meteor

  • 0

Using Yarn with Meteor

Category : Meteor

Yarn’s the npm with a memory; and Meteor is the JavaScript, reactive, database everywhere, platform of your dreams. Too bad they didn’t ‘just work’ together on Windows.

Installing Yarn globally with the meteor install yarn -g command doesn’t add the meteor yarn command, as it does on other OS’s. If you use Yarn outside of meteor yarn, you have to make sure they are in the same Node environment, or you may run into errors like this…

When installing chimp (which then builds bcrypt) using Yarn and Node 7 results in a hung process with output like this:

[3/4] Linking dependencies...
[4/4] Building fresh packages...
[1/4] ? bcrypt: gyp info using node@7.7.1 | win32 | x64
[2/4] ? fibers: node@7.7.1 | win32 | x64
[3/4] ? phantomjs-prebuilt: Found PhantomJS at C:\Projects\LandTen\applicationFiles\node_modules\phantomjs-prebuilt\lib\
[-/4] ? waiting...

that quickly changes to this:

[3/4] Linking dependencies...
[-/4] ? waiting...
[2/4] ? fibers: gyp info spawn args '-Goutput_dir=.' ]
[-/4] ? waiting...
[-/4] ? waiting...

You can see in that first block that node-gyp is using Node 7.7.1. But the version of Node that Meteor is using (I’m running Meteor 1.4.3.1) is Node v4.73.

So what? Big deal! It is a big deal. Any npm packages that require building binaries will require a specific version of node. If you attempt to use a different version of node, they will be built using the wrong C++ files. So I could abandon Yarn, or I could force Yarn to use Node v4.x.

If you’re using Chocolatey, and you should be, you’ll have to uninstall the wrong Node/s and install the right one. Install the same major version of Node on your machine that Meteor is using. Chocolatey offers version 4.6.1. You’ll also have to install Yarn with the ignore-dependencies flag, so Choco won’t automatically install the latest version of node.

choco uninstall yarn nodejs-lts nodejs.install
choco install nodejs.install --version 4.6.1
choco install yarn --ignore-dependencies

and Bob’s your uncle


About Author

mcissel

I'm a full stack web developer / software engineer. I can code a Raspberry Pi or a Windows .NET app, but I'm truly at home on the web, in the cloud, the modern JavaScript "wild west". I've been making code look good since Firefox was called Netscape.

Leave a Reply