Blog about Ruby, Rails, and more!

Using Rails with Yarn on Heroku


One of thee best features of Rails 5.1 is Yarn support. You can easily manage your javascript dependencies just by using yarn add. It's a breeze.......until you push to Heroku.

Heroku dynos use 'buildpacks' which refers to a specific set of tools that your app has access to during a deploy. If you are deploying a Rails app, your default buildpack will be heroku/ruby.

However, since we are trying to deploy a Rails 5.1 app that needs to run yarn install, you will need to add the heroku/nodejs buildpack. The nodejs buildpack will give your app access to the yarn executable during deployment, meaning that you can run yarn install.

To add the nodejs buildpack to your Heroku app, run heroku buildpacks:add --index 1 heroku/nodejs. From the heroku docs:

    This will insert the Node.js buildpack at the first position in the order of buildpack execution,
    and move the other buildpacks that are ahead of it down one position. Thus the Ruby 
    buildpack will now be the second buildpack to run.