What causes undefined method `dir_mode=' when running bundle install

Viewed 1260

I have revisited a Rails 4.2.11.1 app that has not been touched for 2 months. The app uses CircleCI for deployment. Before, when build was triggered, there were no problems whatsoever. During those two months no changes have been made to the code. When triggering a build and running bundle install --deployment --path vendor/bundle, following errors are returned:

#!/bin/bash -eo pipefail
bundle install --deployment --path vendor/bundle
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
/gems/gems/bundler-1.12.5/lib/bundler/rubygems_integration.rb:152: warning: constant Gem::ConfigMap is deprecated
Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Fetching gem metadata from https://rubygems.org/
Fetching version metadata from https://rubygems.org/
Fetching dependency metadata from https://rubygems.org/
Installing rake 12.3.3

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/rake-12.3.3.gem":String
Installing CFPropertyList 2.3.6

NoMethodError: undefined method `dir_mode=' for #<String:0x007f3a884a9100>
Installing i18n 0.8.6

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/i18n-0.8.6.gem":String
Installing minitest 5.14.3

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/minitest-5.14.3.gem":String
Installing thread_safe 0.3.6

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/thread_safe-0.3.6.gem":String
Installing builder 3.2.4

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/builder-3.2.4.gem":String
Installing erubis 2.7.0

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/erubis-2.7.0.gem":String
Installing mini_portile2 2.4.0

NoMethodError: undefined method `dir_mode=' for #<String:0x007f3aa040ce78>
Installing crass 1.0.6

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/crass-1.0.6.gem":String
Installing rack 1.6.13

NoMethodError: undefined method `dir_mode=' for "/root/repo/vendor/bundle/ruby/2.3.0/cache/zonebie-0.6.1.gem":String
An error occurred while installing rake (12.3.3), and Bundler cannot continue.
Make sure that `gem install rake -v '12.3.3'` succeeds before bundling.

Exited with code exit status 5
CircleCI received exit code 5

I have no idea what might be causing the issue with NoMethodError. Trieg searching for dir_mode= method but to no avail. I would really appreciate any hints on how to get rid of this problem. Thanks in advance!

2 Answers

I had the same problems earlier. bundle update --bundler appeared to be what fixed it for me.

I've run into this when using Ruby 2.7 and Bundler 1.9.3. There seems to be an incompatibility between Ruby 2.7 and some older versions of Bundler.

Bundler 2.x will work with gems that are cached (eg. you ran bundle _1.9.3_ install previously), but it throws this error if you try to add / change gems:

> bundle install --verbose

> NoMethodError: undefined method 'dir_mode=' for /xxx/vendor/bundle/ruby/cache/byebug-11.1.3.gem":String
/usr/local/lib/ruby/site_ruby/2.7.0/rubygems/installer.rb:179:in `initialize'
/xxx/vendor/bundle/ruby/gems/bundler-1.9.3/lib/bundler/source/rubygems.rb:114:in `new'

Examining the code listed in the first two lines of the stack above show the problem: RubyGems in Ruby 2.7 is expecting a parameter that responds to dir_mode= but Bundler 1.9.3 is passing in a path string.

After some experimentation, I found that Bundler 1.16.x was compatible, so the basic advice given earlier is correct, you probably need to upgrade Bundler.

Related