Fixing Common Bundler Problems

Posted by Mobomo on August 23, 2010

When bundler first came out, I really wanted to like it. It promised a clean way to declare dependencies for your application in a single and definitive place, regardless of what kind of box your app was running on. Unfortunately, bundler has not lived up to the hype, and I've had plenty of headaches from bundler problems. Read on for a list of tips I've pulled together to save you some headache.

Ensure your local bundler is the same version as your server

Explicitly specify gem versions

Did you know in HTTParty 0.4.5, there is no 'parsed_response' method on a response object? Well, neither did I when it worked fine on my local laptop (0.6.1), but not on the server (0.4.5)

1

gem&quot;httparty&quot;# bad times if your system gem is out of date... gem &quot;httparty&quot;, &quot;~&gt; 0.6.1&quot; # better, but... gem &quot;httparty&quot;, &quot;0.6.1&quot; # ...why not just specify the version everyone should use?

Check that you are actually using gems installed by bundler

Once in a while, bundler will report success on install, but you'll get the wrong gems loaded in your load path. Grep your load path to double check libraries you're having trouble with:

Gemfile conditionals

bundler allows you to specify groups so only gems you need in one environment are loaded:

1

# we don&#39;t call the group :test because we don&#39;t want them auto-required group :test do gem &#39;database_cleaner&#39;, &#39;~&gt; 0.5.0&#39; gem &#39;rspec&#39; gem &#39;rspec-rails&#39;, &#39;~&gt; 1.3.2&#39;, :require =&gt; &#39;spec/rails&#39; end

All gems you specify in your Gemfile WILL be installed regardless of what RAILS_ENV you're currently on. There's a very deceptively named option called –without that does not work as you would expect:

1

# weird, but this will install gems in group test bundle install --without=test

This can turn out to be a disaster if your linux production environment tries to install a OSX specific gem with native extensions that you use for development. An ugly fix in the meantime is to add conditionals that look for an environment variable:

1

if[&#39;test&#39;, &#39;cucumber&#39;].include?(ENV[&#39;RAILS_ENV&#39;]) group :test do # your gems end end

NameErrors and autoloading issues

For some gems, bundler will not autoload properly. If you start getting NameErrors or LoadErrors for a gem, read this issue. The fix is to skip the require in your Gemfile and manually do the require in your environment.rb:

Other

Bundler is in its infancy, and it continues to get better with each release, so many of these issues might not exist in the near future. In the meantime, I hope this list will save you some time with bundler related headaches. Let me know in the comments if you've encountered other tips for resolving these problems.