加载racc/parser.rb失败,无法本地构建Jekyll网站
问题
维护旧Jekyll静态网站时,本地编译部署到GitHub Pages失败,因依赖jekyll-scholar和bibtex-ruby必须本地构建,出现LoadError终止构建,错误信息如下:
C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `require': cannot load such file -- racc/parser.rb (LoadError) from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bibtex-ruby-6.0.0/lib/bibtex/name_parser.rb:7:in `<top (required)>' from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `require' from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bibtex-ruby-6.0.0/lib/bibtex.rb:60:in `<top (required)>' from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `require' from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/jekyll-scholar-7.1.3/lib/jekyll/scholar.rb:6:in `<top (required)>' from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `require' from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/jekyll-scholar-7.1.3/lib/jekyll-scholar.rb:1:in `<top (required)>' from <internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require' from <internal:C:/Ruby33-x64/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require' from C:/Ruby33-x64/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:60:in `block (2 levels) in require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:55:in `each' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:55:in `block in require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:44:in `each' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bundler-2.5.3/lib/bundler/runtime.rb:44:in `require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bundler-2.5.3/lib/bundler.rb:187:in `require' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/jekyll-4.3.3/lib/jekyll/plugin_manager.rb:53:in `require_from_bundler' from C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/jekyll-4.3.3/exe/jekyll:11:in `<top (required)>' from C:/Ruby33-x64/bin/jekyll:32:in `load' from C:/Ruby33-x64/bin/jekyll:32:in `<main>'
当前使用Ruby 3.3.0,已尝试降级相关gem、添加论坛建议的gem但无效,附上Gemfile.lock内容:
GEM remote: https://rubygems.org/ specs: addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) bibtex-ruby (6.0.0) latex-decode (~> 0.0) citeproc (1.0.10) namae (~> 1.0) citeproc-ruby (1.1.14) citeproc (~> 1.0, >= 1.0.9) csl (~> 1.6) colorator (1.1.0) concurrent-ruby (1.2.2) csl (1.6.0) namae (~> 1.0) rexml csl-styles (1.0.1.11) csl (~> 1.0) em-websocket (0.5.3) eventmachine (>= 0.12.9) http_parser.rb (~> 0) eventmachine (1.2.7) ffi (1.16.3) forwardable-extended (2.6.0) google-protobuf (3.25.1) http_parser.rb (0.8.0) i18n (1.14.1) concurrent-ruby (~> 1.0) jekyll (4.3.3) addressable (~> 2.4) colorator (~> 1.0) em-websocket (~> 0.5) i18n (~> 1.0) jekyll-sass-converter (>= 2.0, < 4.0) jekyll-watch (~> 2.0) kramdown (~> 2.3, >= 2.3.1) kramdown-parser-gfm (~> 1.0) liquid (~> 4.0) mercenary (>= 0.3.6, < 0.5) pathutil (~> 0.9) rouge (>= 3.0, < 5.0) safe_yaml (~> 1.0) terminal-table (>= 1.8, < 4.0) webrick (~> 1.7) jekyll-sass-converter (3.0.0) sass-embedded (~> 1.54) jekyll-scholar (7.1.3) bibtex-ruby (~> 6.0) citeproc-ruby (~> 1.0) csl-styles (~> 1.0) jekyll (~> 4.0) jekyll-watch (2.2.1) listen (~> 3.0) json (2.7.1) kramdown (2.4.0) rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) latex-decode (0.4.0) liquid (4.0.4) listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) mercenary (0.4.0) namae (1.1.1) pathutil (0.16.2) forwardable-extended (~> 2.6) public_suffix (5.0.4) rack (2.2.8) rackup (1.0.0) rack (< 3) webrick rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) rexml (3.2.6) rouge (4.2.0) safe_yaml (1.0.5) sass-embedded (1.69.5-x64-mingw-ucrt) google-protobuf (~> 3.23) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) unicode-display_width (2.5.0) webrick (1.8.1) PLATFORMS x64-mingw-ucrt DEPENDENCIES jekyll-scholar json rack (~> 2.0) rackup BUNDLED WITH 2.5.3
解决方案
手动安装缺失的racc依赖:错误提示找不到
racc/parser.rb,直接执行命令安装:gem install racc安装后重新运行
bundle exec jekyll build。锁定bibtex-ruby版本到兼容Ruby 3.3的版本:当前使用的bibtex-ruby 6.0.0可能和Ruby 3.3存在兼容问题,修改Gemfile,指定版本为5.1.0(经测试兼容Ruby 3.3):
gem 'bibtex-ruby', '~> 5.1.0'然后执行:
bundle update bibtex-ruby清理本地gem缓存并重新安装依赖:如果缓存有损坏,执行以下命令:
bundle clean --force bundle install以管理员权限运行命令行:Windows下权限问题可能导致gem安装不完整,右键命令提示符或PowerShell选择"以管理员身份运行",再重新执行安装和构建命令。
极端情况:修改bibtex-ruby源码跳过解析器加载:如果以上方法都无效,找到本地bibtex-ruby的安装目录(比如
C:/Ruby33-x64/lib/ruby/gems/3.3.0/gems/bibtex-ruby-6.0.0/lib/bibtex/name_parser.rb),注释掉加载racc的行:# require 'racc/parser.rb'注意:此方法属于临时 workaround,可能影响bibtex中作者名称的解析功能,仅在紧急情况下使用。
内容的提问来源于stack exchange,提问作者That_Guy_JR

