bundle exec jekyll serve:无法加载此文件

45

我正在尝试为Github Page / Jekyll站点做出贡献,想要能够在本地可视化更改,但是当我运行bundle exec jekyll serve时,会得到以下输出:

bundler: failed to load command: jekyll (/usr/local/lib/ruby/gems/3.0.0/bin/jekyll)
/usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/html.rb:10:in `require': cannot load such file -- rexml/parsers/baseparser (LoadError)
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/html.rb:10:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/html.rb:10:in `require'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/html.rb:10:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/paragraph.rb:14:in `require'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/paragraph.rb:14:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:345:in `require'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:345:in `<class:Kramdown>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:60:in `<module:Parser>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:19:in `<module:Kramdown>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown.rb:17:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/lib/jekyll/converters/smartypants.rb:3:in `require'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/lib/jekyll/converters/smartypants.rb:3:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/lib/jekyll.rb:13:in `require'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/lib/jekyll.rb:13:in `block in require_all'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/lib/jekyll.rb:12:in `each'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/lib/jekyll.rb:12:in `require_all'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/lib/jekyll.rb:194:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/exe/jekyll:8:in `require'
        from /usr/local/lib/ruby/gems/3.0.0/gems/jekyll-3.8.5/exe/jekyll:8:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/bin/jekyll:23:in `load'
        from /usr/local/lib/ruby/gems/3.0.0/bin/jekyll:23:in `<top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/cli/exec.rb:63:in `load'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/cli/exec.rb:28:in `run'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/cli.rb:494:in `exec'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/cli.rb:30:in `dispatch'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/cli.rb:24:in `start'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/exe/bundle:49:in `block in <top (required)>'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/lib/bundler/friendly_errors.rb:130:in `with_friendly_errors'
        from /usr/local/lib/ruby/gems/3.0.0/gems/bundler-2.2.5/exe/bundle:37:in `<top (required)>'
        from /usr/local/opt/ruby/bin/bundle:23:in `load'
        from /usr/local/opt/ruby/bin/bundle:23:in `<main>'

我运行了bundle update命令,得到以下结果:

Using concurrent-ruby 1.1.8 (was 1.1.7)
Using multi_json 1.15.0
Using public_suffix 3.1.1
Using latex-decode 0.3.2
Using bundler 2.2.5
Using coffee-script-source 1.11.1
Using execjs 2.7.0
Using colorator 1.1.0
Using namae 1.0.2 (was 1.0.1)
Using unf_ext 0.0.7.7
Using http_parser.rb 0.6.0
Using faraday-net_http 1.0.1
Using multipart-post 2.1.1
Using ruby2_keywords 0.0.4
Using forwardable-extended 2.6.0
Using gemoji 3.0.1
Using rb-fsevent 0.10.4
Using kramdown 1.17.0
Using liquid 4.0.3
Using mercenary 0.3.6
Using rouge 3.13.0
Using safe_yaml 1.0.5
Using racc 1.5.2
Using jekyll-paginate 1.1.0
Using rubyzip 2.3.0
Using jekyll-swiss 1.0.0
Using unicode-display_width 1.7.0
Using i18n 0.9.5
Using coffee-script 2.4.1
Using citeproc 1.0.10
Using csl 1.5.2
Using unf 0.1.4
Using eventmachine 1.2.7
Using citeproc-ruby 1.1.13 (was 1.1.12)
Using activesupport 3.2.22.5
Using csl-styles 1.0.1.10
Using simpleidn 0.2.1 (was 0.1.1)
Using faraday 1.3.0 (was 1.0.1)
Using addressable 2.7.0
Using pathutil 0.16.2
Using jekyll-coffeescript 1.1.1
Using nokogiri 1.11.1 (x86_64-darwin) (was 1.10.10)
Using terminal-table 1.8.0
Using bibtex-ruby 4.4.7
Using em-websocket 0.5.2
Using dnsruby 1.61.5 (was 1.61.4)
Using html-pipeline 2.14.0
Using ffi 1.14.2 (was 1.13.1)
Using sawyer 0.8.2
Using ethon 0.12.0
Fetching ruby-enum 0.9.0 (was 0.8.0)
Using typhoeus 1.4.0
Using octokit 4.20.0 (was 4.18.0)
Using rb-inotify 0.10.1
Using github-pages-health-check 1.16.1
Using sass-listen 4.0.0
Using listen 3.4.1 (was 3.2.1)
Using jekyll-gist 1.5.0
Using sass 3.7.4
Using jekyll-watch 2.2.1
Using jekyll-sass-converter 1.5.2
Using jekyll 3.8.5
Using jekyll-avatar 0.7.0
Using jekyll-github-metadata 2.13.0
Using jekyll-mentions 1.5.1
Using jekyll-optional-front-matter 0.3.2
Using jekyll-readme-index 0.3.0
Using jekyll-redirect-from 0.15.0
Using jekyll-relative-links 0.6.1
Using jekyll-remote-theme 0.4.1
Using jekyll-seo-tag 2.6.1
Using jekyll-sitemap 1.4.0
Using jekyll-titles-from-headings 0.5.3
Using jemoji 0.11.1
Using jekyll-scholar 5.16.0
Using jekyll-feed 0.13.0
Using jekyll-theme-cayman 0.1.1
Using jekyll-theme-dinky 0.1.1
Using jekyll-theme-hacker 0.1.1
Using jekyll-theme-leap-day 0.1.1
Using jekyll-theme-merlot 0.1.1
Using jekyll-default-layout 0.1.4
Using jekyll-theme-minimal 0.1.1
Using jekyll-theme-midnight 0.1.1
Using jekyll-theme-primer 0.5.4
Using jekyll-theme-slate 0.1.1
Using jekyll-theme-tactile 0.1.1
Using jekyll-theme-modernist 0.1.1
Using jekyll-theme-time-machine 0.1.1
Using minima 2.5.1
Using jekyll-theme-architect 0.1.1
Installing ruby-enum 0.9.0 (was 0.8.0)
Using commonmarker 0.17.13
Using jekyll-commonmark 1.3.1
Using jekyll-commonmark-ghpages 0.1.6
Using github-pages 204
Bundle updated!

另外,这是gemfile的样子:

source "https://rubygems.org"
gem 'jekyll-scholar', group: :jekyll_plugins

# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
gem "github-pages", "~> 204", group: :jekyll_plugins

# If you have any plugins, put them here!
group :jekyll_plugins do
  gem "jekyll-feed", "~> 0.6"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

# Performance-booster for watching directories on Windows
gem "wdm", "~> 0.1.0" if Gem.win_platform?

为什么它不工作?我对Ruby和Jekyll/Github Pages相当新,但我创建了另一个Github页面的网站,并且这些命令都可以正常使用...


2
我遇到了与“rexml/parsers/baseparser”相同的错误。 我已将我的Gemfile升级到github-pages 212(以及jekyll 3.9.0和jekyll-feed 0.15.1)。 - choas
谢谢!这个方法有效!我之前不知道运行 bundle update 并不能直接将项目中使用的所有 gem 更新到最新版本。再次感谢! - tukanium
9个回答

56

我之前也遇到了同样的问题,后来在https://github.com/jekyll/jekyll/issues/8523上找到了一个解决方法。

在你的网站的Gemfile文件中加入gem "webrick",然后运行bundle install

这时候你可以运行bundle exec jekyll serve

对于我来说,它起作用了!


4
谢谢您的回答!这个方法适用于我的第一个网站,但很遗憾对于这个网站不起作用。 - tukanium
3
和 @tukanium 一样的问题,添加 webrick 也无法解决问题。 - random_coder_101

17
我也遇到了这个错误。解决方案在文档中已经有了。
如果你使用的是Ruby版本3.0.0或更高的版本,第5步可能会失败(bundle exec jekyll serve)。你可以通过将webrick添加到你的依赖项中来修复它:bundle add webrick 或者将 gem "webrick" 添加到 Gemfile中,然后运行 bundle install

重要的细节是升级到Ruby 3。在将项目更新到Ruby 3.0.4之后,我不得不添加webrick以解决错误。 - Francisco Quintero

15

以下是我如何通过@ choas的评论解决它:

  1. 运行 gem install github-pages, gem install jekyllgem install jekyll-feed 更新github-pages、jekyll和jekyll-feed gems。 我必须执行这个步骤,因为简单的 bundle update 没有安装最新版本。
  2. 将Gemfile中的这些gems修改为最新版本。
  3. 运行 bundle update
  4. 最后运行 bundle exec jekyll serve

我不确定所有这些步骤是否都是多余的,因为我对Ruby / Github Pages / Jekyll并不非常熟悉,但它确实起作用。


我确实需要从Gemfile中移除Jekyll的固定版本,然后运行更新,这样才能让它对我起作用。 - undefined
我还不得不升级到Ruby 3,但由于我仍在使用苹果原生版本,所以这是不被允许的,因此我也不得不进行更改。我会添加另一个答案来补充这些步骤。 - undefined

8
我看到你正在使用 github-pages:204jekyll:3.8.5
我用相同的依赖项让我的项目运行起来了:
  1. bundle update github-pages
  2. bundle add webrick

bundle add webrick 使我通过了最初的错误。现在出现“无法加载文件--3.0 / rubyeventmachine(LoadError)” 的错误信息。不幸的是,“bundle add rubyeventmachine” 没有起作用。 - SeaDude

4
  1. 安装 webrick 和 jekyll-mentions:打开终端,输入 gem install webrick,然后输入 gem install jekyll-mentions
  2. 打开你的 gem 文件,在插件部分添加 gem "jekyll-mentions"gem "webrick"
group :jekyll_plugins do
  gem "jekyll-mentions", "1.6.0"
  gem "webrick"
end
  1. 返回终端并执行bundle install命令。

我想你就可以开始使用了。这个过程对我很有用!


3

只需在gemfile中删除特定版本的jekyll,因为这种特定性会导致与kramdown包的依赖关系问题。

gem "jekyll", "~> 3.2.1"

删除特定版本的jekyll,操作如下:
gem "jekyll"

在Gemfile中添加webrick gem

gem "webrick"

重新运行bundler。
bundler

最后,提供服务。
bundle exec jekyll serve --livereload

没有。没有修好它。 - Ken Ingram

1

非常感谢,你的帮助让我的工作正常运行。显然,我还需要一堆其他插件,所以我的有效的Gemfile jekyll_plugins看起来像这样:

group :jekyll_plugins do
  gem "jekyll-feed"
  gem "jekyll-mentions"
  gem "webrick"
  gem "jekyll-redirect-from"
  gem "jekyll-sitemap"
  gem "jekyll-avatar"
  gem "jemoji"
end

然后执行 bundle install; bundle exec jekyll serve


0
@tukanium的解决方案对我有效,不过我还需要升级到Ruby 3,但由于我仍在运行Apple原生版本,所以这也需要改变。
以下是步骤:
  1. 安装Ruby:brew install ruby
  2. 检查版本:ls /usr/local/lib/ruby/gems/
  3. 添加到路径(更改版本):echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc
  4. 检查是否成功:which ruby
  5. 重新初始化终端:zsh
  6. 通过运行gem install github-pagesgem install jekyllgem install jekyll-feed更新github-pages、jekyll和jekyll-feed gems。我必须执行这一步,因为简单的bundle update无法安装最新版本。
  7. 添加webrick:bundle add webrick
  8. 在Gemfile中删除所有版本号(将自动更新为最新版本)
  9. 运行bundle update
  10. 最后运行bundle exec jekyll serve

0
安装了一个宝石,但是看到`bundle exec`抱怨它丢失似乎是一件很少见的事情。虽然我的问题与另一个应用程序(passenger)有关,但这是我在这个主题上找到的最好的帖子。我在这里发布我的解决方案,以便其他人可以找到它。
当我用`bundle exec `启动时,我的应用程序抱怨缺少一个库,尽管它明确安装了。
我发现这个库需要在我运行bundle命令的目录中的`Gemfile`中提到。
在我的设置中,我有两个Ruby项目:一个REST接口(sinatra/passenger)和一个包含业务逻辑的自定义库。这两个项目都有自己的Gemfile。相关的库被业务逻辑使用,所以它在那个Gemfile中。由于某种原因,启动passenger会崩溃,并抱怨缺少该库。
只有在我将该库添加到两个项目的Gemfile中后,问题才消失。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接