0

I'm running into an issue with my Jekyll/Gulp setup failing, and the message I keep getting is "must use Bundler 2 or greater" even though I have Bundler 2.0.2 installed. There are other questions out there with a similar problem, but those projects were Rails and Heroku based. So far none of the solutions I've found ended up not working for me.

Terminal shows that I have the same version of Bundler installed as what's listed in Gemfile.lock.

fs-217-156:jekyll-gulp mrjandre$ bundler -v
Bundler version 2.0.2

And I'm running Ruby 2.6.5:

fs-217-156:jekyll-gulp mrjandre$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin17]

From Gemfile.lock:

PLATFORMS
  ruby
  x64-mingw32

DEPENDENCIES
  jekyll (~> 3.8.5)
  jekyll-feed (~> 0.6)
  tzinfo-data

BUNDLED WITH
   2.0.2

I've tried uninstalling and reinstalling Bundler and Jekyll at least a dozen times over the last couple of days.

gem uninstall bundler
gem install bundler -v '2.0.2'
gem update --system
bundle update --bundler

No idea what binstubs are, but I gave this a try too:

bundle binstubs bundler

Results of running 'gulp':

fs-217-156:jekyll-gulp mrjandre$ gulp
[09:48:24] Using gulpfile ~/Desktop/Repos/jekyll-gulp/gulpfile.js
[09:48:24] Starting 'default'...
[09:48:24] Starting 'styles'...
[09:48:25] Finished 'styles' after 928 ms
[09:48:25] Starting 'scripts'...
[09:48:27] Finished 'scripts' after 1.35 s
[09:48:27] Starting 'images'...
[09:48:27] Finished 'images' after 3.84 ms
[09:48:27] Starting 'jekyll-build'...
Traceback (most recent call last):
    13: from /usr/local/bin/jekyll:22:in `<main>'
    12: from /usr/local/bin/jekyll:22:in `load'
    11: from /usr/local/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/exe/jekyll:11:in `<top (required)>'
    10: from /usr/local/lib/ruby/gems/2.6.0/gems/jekyll-4.0.0/lib/jekyll/plugin_manager.rb:52:in `require_from_bundler'
     9: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler.rb:101:in `setup'
     8: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler.rb:135:in `definition'
     7: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/definition.rb:34:in `build'
     6: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/dsl.rb:13:in `evaluate'
     5: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/dsl.rb:234:in `to_definition'
     4: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/dsl.rb:234:in `new'
     3: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/definition.rb:83:in `initialize'
     2: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/definition.rb:83:in `new'
     1: from /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/lockfile_parser.rb:95:in `initialize'
/usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/bundler/lockfile_parser.rb:108:in `warn_for_outdated_bundler_version': You must use Bundler 2 or greater with this lockfile. (Bundler::LockfileError)
[09:48:27] 'jekyll-build' errored after 612 ms
[09:48:27] Error: exited with error code: 1
    at ChildProcess.onexit (/Users/mrjandre/Desktop/Repos/jekyll-gulp/node_modules/end-of-stream/index.js:39:36)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
[09:48:27] 'default' errored after 2.9 s

This is the jekyll-build task in gulpfile.js, which is pretty standard:

gulp.task("jekyll-build", function () {
  return cp.spawn( jekyll , ["build"], {stdio: "inherit"})
});

I also deleted node_modules and reinstalled those dependencies a few times, ran npm audit fix and updated npm as well.

I switch between Mac OSX and Windows 10 often, and this setup has been reliable on both systems for years. Any pointers and suggestions would be greatly appreciated, and I'd be happy to provide additional information if I've missed something.

Mike Jandreau
  • 392
  • 3
  • 16

1 Answers1

0

Edit: The Homebrew misconfiguration issue was fixed 2019-10-30.

If you installed Jekyll as per Jekyll on macOS instructions you got Ruby 2.6.5 via Homebrew, and then the underlying problem is that Homebrew (until 2019-10-30) misconfigured RubyGems making it more or less impossible to get Ruby to load newer versions of any of Ruby's default gems such as bundler.

The misconfiguration is in overriding the default_dir in the RubyGems customization point /usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/rubygems/defaults/operating_system.rb in an apparent attempt to move the 'standard' gem installation folder to /usr/local/lib/ruby/gems/2.6.0.

However, the default_dir needs to point to /usr/local/Cellar/ruby/2.6.5/lib/ruby/gems/2.6.0 because it contains the specifications/default folder with the default gem specs. If the default gems cannot be loaded from Gem::Specification::default_specifications_dir then RubyGems' overriding of require won't activate newer versions of default Gems, even if they are installed and found, which prevents loading of bundler 2.0.2. Non-default gems such as Jekyll still load as expected.

With the Homebrew RubyGems misconfiguration, the resulting problem is that the bundler command in your path will be a user-installed v2.0.2, since you did gem install --user-install bundler jekyll and added the user installation path ($HOME/.gem/ruby/2.6.0/bin) to your $PATH, whereas the jekyll command only sees and uses the default bundler gem v1.17.2 due to the misconfiguration - and these version mismatches causes your issues.

Waiting for Homebrew to fix the Ruby formula, one can fix the misconfiguration in operating_system.rb by replacing it with the following.

module Gem
  class << self
    alias :old_default_dir :default_dir
    alias :old_default_path :default_path
    alias :old_default_bindir :default_bindir
    alias :old_ruby :ruby
  end

  def self.homebrew_gems_dir
    path = [
      "/usr/local",
      "lib",
      "ruby",
      "gems",
      "2.6.0"
    ]
    File.join(*path)
  end

  def self.default_path
    path = []
    path << homebrew_gems_dir
    path << user_dir if user_home && File.exist?(user_home)
    path << default_dir
    path << vendor_dir if vendor_dir and File.directory? vendor_dir
    path
  end

  def self.default_bindir
    "/usr/local/lib/ruby/gems/2.6.0/bin"
  end

  def self.ruby
    "/usr/local/opt/ruby/bin/ruby"
  end
end

(assuming you haven't changed the HOMEBREW_PREFIX away from /usr/local)

See also this related Homebrew issue and this answer.

marhel
  • 11
  • 1
  • 4