Bundler "failed to load command: rspec" in CI
bundle exec found the command but could not run it. Either the gem providing the executable is not in the bundle, or the program raised an exception while loading. The line just below this message names the real error.
What this error means
bundle exec rspec (or another tool) fails with "bundler: failed to load command: rspec (/path/to/rspec)" followed by an underlying error. The wrapper is generic; the cause is in the lines beneath it.
bundler: failed to load command: rspec (/app/vendor/bundle/ruby/3.3.0/bin/rspec)
/app/vendor/bundle/.../rspec-core-3.13.0/lib/rspec/core.rb:1:in `require':
cannot load such file -- rspec/support (LoadError)Common causes
Executable’s gem missing or partial in the bundle
The gem providing the command is not declared, is in an excluded group, or installed incompletely, so bundle exec cannot load it.
An exception while loading the command
The command starts loading and raises (a missing require, a bad config file, a dependency LoadError). The underlying message below the wrapper is the actual fault.
How to fix it
Read the underlying error
- Look at the line immediately below "failed to load command" - that is the real cause.
- A LoadError means a gem/file is missing from the bundle; add it to the Gemfile.
- A config or runtime error means fix that file, not Bundler.
Ensure the command’s gem is in the bundle
Declare the gem in a group that is installed, then reinstall.
# Gemfile
group :test do
gem 'rspec'
end
# then
bundle install
bundle exec rspecHow to prevent it
- Declare every executable gem in an installed group.
- Do not exclude the test group in jobs that run the test command.
- Keep Gemfile.lock committed so the bundle is complete and reproducible.