You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Github Actions中mini_racer gem安装失败问题求助

问题:Github Actions CI中mini_racer gem安装失败(无代码变更)

2023年10月9日周一上班时,项目的Github Actions CI突然无法正常运行,原因是mini_racer gem安装失败。该CI在10月6日周五还能正常工作,期间无人推送任何代码变更,怀疑是Github的环境发生了变化。

完整报错日志

安装 dartsass-rails 0.3.0
Gem::Ext::BuildError: 错误:构建gem原生扩展失败。

当前目录:
/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/gems/mini_racer-0.6.3/ext/mini_racer_extension
/opt/hostedtoolcache/Ruby/3.0.3/x64/bin/ruby -I
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0 -r
./siteconf20231009-2476-stlahy.rb extconf.rb
检查 -lpthread... 是
*** extconf.rb 执行失败 ***
无法创建Makefile,可能是缺少必要的库或头文件。查看mkmf.log文件获取更多详情。你可能需要配置选项。

提供的配置选项:
  --with-opt-dir
  --without-opt-dir
  --with-opt-include
  --without-opt-include=${opt-dir}/include
  --with-opt-lib
  --without-opt-lib=${opt-dir}/lib
  --with-make-prog
  --without-make-prog
  --srcdir=.
  --curdir
  --ruby=/opt/hostedtoolcache/Ruby/3.0.3/x64/bin/$(RUBY_BASE_NAME)
  --with-pthread-dir
  --without-pthread-dir
  --with-pthread-include
  --without-pthread-include=${pthread-dir}/include
  --with-pthread-lib
  --without-pthread-lib=${pthread-dir}/lib
  --with-pthreadlib
  --without-pthreadlib
  --enable-debug
  --disable-debug
  --enable-asan
  --disable-asan
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/psych.rb:457:in
`parse_stream': 未定义方法 `parse' 用于 #<Psych::Parser:0x0000563746cb82d8
@handler=#<Psych::Handlers::DocumentStream:0x0000563746cb83f0 @stack=[],
@last=nil, @root=nil, @start_line=nil, @start_column=nil, @end_line=nil,
@end_column=nil, @block=#<Proc:0x0000563746cb8328
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/psych.rb:391>>,
@external_encoding=0> (NoMethodError)
  来自 /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/psych.rb:391:in `parse'
来自 /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/psych.rb:280:in
`unsafe_load'
来自
/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/gems/libv8-node-16.10.0.0-x86_64-linux/ext/libv8-node/location.rb:21:in
`block in load!'
来自
/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/gems/libv8-node-16.10.0.0-x86_64-linux/ext/libv8-node/location.rb:20:in
`open'
来自
/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/gems/libv8-node-16.10.0.0-x86_64-linux/ext/libv8-node/location.rb:20:in
`load!'
来自
/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/gems/libv8-node-16.10.0.0-x86_64-linux/lib/libv8/node.rb:8:in
`configure_makefile'
  来自 extconf.rb:77:in `<main>'

要查看扩展编译失败的原因,请查看mkmf.log文件,路径如下:

/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/extensions/x86_64-linux/3.0.0/mini_racer-0.6.3/mkmf.log

extconf执行失败,退出码1

Gem文件将保留在以下位置供检查:
/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/gems/mini_racer-0.6.3
结果记录到:
/home/runner/work/myproject/myproject/vendor/bundle/ruby/3.0.0/extensions/x86_64-linux/3.0.0/mini_racer-0.6.3/gem_make.out

/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/ext/builder.rb:93:in
`run'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/ext/ext_conf_builder.rb:47:in
`block in build'
  /opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/tempfile.rb:317:in `open'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/ext/ext_conf_builder.rb:26:in
`build'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/ext/builder.rb:159:in
`build_extension'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/ext/builder.rb:193:in
`block in build_extensions'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/ext/builder.rb:190:in
`each'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/ext/builder.rb:190:in
`build_extensions'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/3.0.0/rubygems/installer.rb:845:in
`build_extensions'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/rubygems_gem_installer.rb:72:in
`build_extensions'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/source/rubygems.rb:202:in
`install'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/installer/gem_installer.rb:54:in
`install'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/installer/parallel_installer.rb:156:in
`do_install'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/installer/parallel_installer.rb:147:in
`block in worker_pool'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/worker.rb:62:in
`apply_func'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/worker.rb:57:in
`block in process_queue'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/worker.rb:54:in
`loop'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/worker.rb:54:in
`process_queue'
/opt/hostedtoolcache/Ruby/3.0.3/x64/lib/ruby/gems/3.0.0/gems/bundler-2.4.19/lib/bundler/worker.rb:90:in
`block (2 levels) in create_threads'

安装mini_racer (0.6.3)时发生错误,Bundler无法继续。

在Gemfile中:
  mini_racer
错误:进程 '/opt/hostedtoolcache/Ruby/3.0.3/x64/bin/bundle' 退出码为5

问题分析

核心错误是未定义方法 'parse' 用于 #<Psych::Parser:...>,这是因为旧版本的mini_racer(0.6.3)依赖的libv8-node与Github Actions环境中更新后的Ruby Psych库不兼容。结合无代码变更但CI突然失败的情况,大概率是Github更新了runner环境中的Ruby或系统依赖版本。

解决方法

  • 升级mini_racer版本:将Gemfile中的mini_racer版本更新至>=0.7.0,新版本修复了与Psych库的兼容性问题。执行bundle update mini_racer后提交变更即可。
  • 锁定Github Actions runner镜像:在CI配置文件中指定使用特定版本的Ubuntu镜像,例如:
    jobs:
      build:
        runs-on: ubuntu-22.04 # 而非默认的最新镜像
    
  • 升级Ruby版本:将项目使用的Ruby版本升级至3.0.x系列的最新补丁版本,或更高稳定版本,修复Psych库的相关兼容性问题。

内容的提问来源于stack exchange,提问作者equivalent8

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 03:00:57