Skip to content
Latchkey

Bundler::GemRequireError in CI

Bundler.require auto-loads every gem in the relevant groups. One of them raised while being required, and Bundler wraps that in a GemRequireError naming the offending gem.

What this error means

Boot fails with Bundler::GemRequireError naming a gem, with the underlying error nested below. It often appears after a gem upgrade, a missing native dependency, or an incompatible Ruby version.

bundler
Bundler::GemRequireError: There was an error while trying to load
the gem 'nokogiri'.
Gem Load Error is: cannot load such file -- nokogiri/nokogiri

Common causes

Native extension not built for the runner

A gem with a C extension was installed for a different platform/Ruby, so its compiled object is missing when required on the runner.

Gem incompatible with the Ruby version

The installed gem version does not support the Ruby CI runs, and it errors at require time.

App code in the gem load path raises

An initializer or required file triggered during Bundler.require raises (e.g. a missing constant or bad config).

How to fix it

Read the nested error and address it

  1. Look at the "Gem Load Error is:" line under the wrapper for the real cause.
  2. Reinstall native gems for the runner platform: bundle config set force_ruby_platform, or bundle install with build tools present.
  3. Align the gem version with the Ruby version CI uses.

Force a clean platform-correct install

Terminal
bundle config set --local force_ruby_platform false
rm -rf vendor/bundle
bundle install

How to prevent it

  • Match gem versions to the Ruby version CI runs.
  • Cache the bundle keyed on platform and Ruby version, not just the lockfile.
  • Install required system build tools before bundle install for native gems.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →