Recently, I’ve had to troubleshoot some build errors during deployments with Heroku. 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:

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

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>