Bundler ignoring BUNDLE_WITHOUT
10 Aug 2021 in TIL
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:
rubysource "https://rubygems.org"group :test, :development dogem "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 installUsing bundler 1.17.2Using diff-lcs 1.4.4Using rspec-support 3.10.2Using rspec-core 3.10.1Using rspec-expectations 3.10.1Using rspec-mocks 3.10.2Using rspec 3.10.0Bundle 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 installUsing bundler 2.2.25Using diff-lcs 1.4.4Using rspec-support 3.10.2Using rspec-core 3.10.1Using rspec-expectations 3.10.1Using rspec-mocks 3.10.2Using rspec 3.10.0Bundle 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.