Debugging Heroku build slug sizes

Debugging Heroku build slug sizes

Recently, I troubleshot build errors during deployments with Heroku.

Heroku slug size growing

The Heroku build was getting bigger with every release, and we were seeing errors such as:

Warning: Your slug size (446 MB) exceeds our soft limit (300 MB) which may affect boot time.

I had to regularly clear the build cache with these commands:

heroku plugins:install heroku-builds
heroku builds:cache:purge -a example-app

How to debug Heroku slug contents

As I was unable to find information online about something like this, I asked on StackOverflow if anyone knew how to debug Heroku build sizes. It turns out there is a way to download the complete Heroku “slug”, that is to say the package that Heroku pushes to servers.

Here are some useful commands:

# list latest Heroku builds
heroku slugs -a <app_name> | head

# downloads a build
heroku slugs download -a <app_name> <slug_id>

# show directory sizes
du -sch *

# shows filenames that changed
diff -qr <dir1> <dir2>

Using these commands, I was able to see that one of our NPM packages, the Webpack Terser Plugin, had a cache option that was turned on. Heroku in turn cached what the Webpack plugin cached, to infinity. Turning the cache option of Webpack Terser Plugin off solved the problem we were experiencing.