My slug size is too large. How can I make it smaller?

Issue

You are receiving warnings that your slug is too large, and now your application will not build.

Resolution

Slugs on Heroku consist of your application and all its dependencies, as well as any other dependencies that may be installed by the buildpacks you have specified for your application.

The maximum allowed slug size (after compression) is 500MB. Slug size varies greatly depending on what language and framework you are using, how many dependencies you have added and other factors specific to your app. Smaller slugs can be transferred to the dyno manager more quickly, allowing for more immediate scaling. You should try to keep your slugs as small and nimble as possible.

You can try and reduce your slug size in a number of ways. The easiest is to add a .slugignore file to your application to tell the slug compiler to ignore any unnecessary files in your application, such as static assets.

To determine what files/folders are taking up space in your slug you can inspect you slug by starting up a one-off dyno like so:

heroku run bash -a <appname>

Once in the dyno you can use the du -ha --max-depth 1 /app | sort -hr command to show the files and folders in the current directory, ordered by (uncompressed) size:

~ $ du -ha --max-depth 1 /app | sort -hr
108M    /app
99M     /app/vendor
8.1M    /app/.heroku
448K    /app/lib
292K    /app/spec
8.0K    /app/Gemfile.lock
4.0K    /app/Procfile
4.0K    /app/Gemfile

This can be helpful in determining where large files are.

You may also find that clearing the build cache helps reduce the size of the slug.

The slug size limit can be increased, although we have seen that slug sizes above 1GB can cause a dyno to fail to boot. We encourage you to keep your slug sizes under 500MB, increase requests can be made by creating a new ticket stating what you would like the limit to be raised to and will be considered on a case-by-case basis.

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support