【问题标题】:Bundler 2.0.2 and Jekyll/Gulp installed, still getting "must use Bundler 2 or greater" messageBundler 2.0.2 和 Jekyll/Gulp 已安装,仍然收到“必须使用 Bundler 2 或更高版本”消息
【发布时间】:2019-10-09 14:36:41
【问题描述】:

我遇到了 Jekyll/Gulp 设置失败的问题,并且我不断收到的消息是“必须使用 Bundler 2 或更高版本”,即使我安装了 Bundler 2.0.2。还有其他类似问题的问题,但这些项目是基于 Rails 和 Heroku 的。到目前为止,我发现的所有解决方案都对我不起作用。

终端显示我安装了与 Gemfile.lock 中列出的相同版本的 Bundler。

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

我正在运行 Ruby 2.6.5:

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

来自 Gemfile.lock:

PLATFORMS
  ruby
  x64-mingw32

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

BUNDLED WITH
   2.0.2

在过去的几天里,我已经尝试卸载和重新安装 Bundler 和 Jekyll 至少十几次。

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

不知道binstubs 是什么,但我也试了一下:

bundle binstubs bundler

运行 '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

这是gulpfile.js中的jekyll-build任务,相当标准:

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

我还删除了 node_modules 并重新安装了几次依赖项,运行 npm audit fix 并更新了 npm。

我经常在 Mac OSX 和 Windows 10 之间切换,而且这种设置多年来在这两个系统上都很可靠。任何指针和建议将不胜感激,如果我错过了什么,我很乐意提供更多信息。

【问题讨论】:

    标签: javascript ruby gulp jekyll bundler


    【解决方案1】:

    编辑:Homebrew misconfiguration issue 已于 2019 年 10 月 30 日修复。

    如果您按照Jekyll on macOS instructions 安装了 Jekyll,那么您通过 Homebrew 获得了 Ruby 2.6.5,那么潜在的问题是 Homebrew(直到 2019-10-30)错误配置了 RubyGems,从而或多或少地无法加载 Ruby任何Ruby's default gems 的较新版本,例如bundler。

    错误配置是覆盖RubyGems customization point/usr/local/Cellar/ruby/2.6.5/lib/ruby/2.6.0/rubygems/defaults/operating_system.rb 中的default_dir,显然是试图将“标准”gem 安装文件夹移动到/usr/local/lib/ruby/gems/2.6.0。

    但是,default_dir 需要 指向 /usr/local/Cellar/ruby/2.6.5/lib/ruby/gems/2.6.0,因为它包含具有默认 gem 规范的 specifications/default 文件夹。 如果无法从Gem::Specification::default_specifications_dir 加载默认gem,那么RubyGems 覆盖require 将不会激活较新版本的默认Gems,即使它们已安装并找到,这会阻止加载bundler 2.0.2。 Jekyll 等非默认 gem 仍按预期加载。

    由于 Homebrew RubyGems 配置错误,导致的问题是路径中的 bundler 命令将是用户安装的 v2.0.2,因为您执行了 gem install --user-install bundler jekyll 并将用户安装路径 ($HOME/.gem/ruby/2.6.0/bin) 添加到您的 $PATH,而由于配置错误,jekyll 命令只能看到和使用默认的捆绑器 gem v1.17.2 - 这些版本不匹配会导致您的问题。

    等待 Homebrew 修复 Ruby 公式,可以通过将其替换为以下内容来修复 operating_system.rb 中的错误配置。

    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
    

    (假设您没有将 HOMEBREW_PREFIX 更改为远离 /usr/local)

    另见此相关的Homebrew issue 和this answer。

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 1970-01-01
      • 2019-04-13
      • 1970-01-01
      • 2020-07-04
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多