Using Yarn for Bower components

As you might know, Facebook introduced Yarn in the beginning of October 2016. A new package / dependency manager for Javascript modules. It replaces both NPM and Bower. So their website states.

It seems though that when you “yarn install” (or just “yarn”), either your existing bower_components folder is emptied (the folder itself is not deleted), or, if you are working with a fresh project, no Bower packages are being retrieved.

This is something the folks at Yarn are working on, but in the meantime, there is a workaround for this (as of Yarn v.0.16). Add the following snippet to your package.json file and “bower install” is called after you “yarn install”:

"scripts": {
    "postinstall": "bower install"
}

This way you still have the benefit of only needing to call one program to get in your Javascript dependencies.

UPDATE Nov 3rd 2016: The developers of Yarn decided to drop Bower support (see GitHub). So now the workaround becomes the only option to use Yarn for both your package.json and bower.json.

1 Response

  1. Jason O'Neil says:

    Thanks! I was wondering what had happened to my bower_components folder…