Bundler ignoring BUNDLE_WITHOUT

10 Aug 2021 in TIL

If you've previously specified `BUNDLE_WITHOUT` make sure that it's not cached in `.bundle/config`

Whilst investigating why BUNDLE_WITHOUT was not ignoring my development dependencies, I noticed that even when I figured out the problem, bundler was not accepting my input for BUNDLE_WITHOUT.

Given the following Gemfile:

ruby
source "https://rubygems.org"
group :test, :development do
gem "rspec"
end

Running BUNDLE_WITHOUT="test" bundle install will still install rspec as it's in both the development and test groups.

bash
❯ BUNDLE_WITHOUT="test" bundle install
Using bundler 1.17.2
Using diff-lcs 1.4.4
Using rspec-support 3.10.2
Using rspec-core 3.10.1
Using rspec-expectations 3.10.1
Using rspec-mocks 3.10.2
Using rspec 3.10.0
Bundle complete! 1 Gemfile dependency, 7 gems now installed.
Gems in the group 'test' were not installed.
Bundled gems are installed into `./vendor/bundle`

So, I update my command to exclude both of those groups, but the gems are still installed:

ruby
BUNDLE_WITHOUT="test:development" bundle install
Using bundler 2.2.25
Using diff-lcs 1.4.4
Using rspec-support 3.10.2
Using rspec-core 3.10.1
Using rspec-expectations 3.10.1
Using rspec-mocks 3.10.2
Using rspec 3.10.0
Bundle complete! 1 Gemfile dependency, 7 gems now installed.
Gems in the group 'test' were not installed.
Bundled gems are installed into `./vendor/bundle`

The issue here is that BUNDLE_WITHOUT was cached after my first run in .bundle/config:

bash
❯ cat .bundle/config
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "test"

The solution is to remove the BUNDLE_WITHOUT line in .bundle/config and re-run your command.