Ruby "rake aborted! LoadError" in CI - Fix the Missing Require
rake failed while loading the Rakefile because a require could not be resolved. A gem the Rakefile needs is not in the bundle, or a required file is not on the load path - and rake was likely not run through Bundler.
What this error means
A rake task aborts with "rake aborted! LoadError: cannot load such file -- <name>" and a backtrace into the Rakefile. The task never runs because loading the Rakefile fails first.
rake aborted!
LoadError: cannot load such file -- rspec/core/rake_task
/app/Rakefile:4:in `require'
(See full trace by running task with --trace)Common causes
A required gem is not in the bundle
The Rakefile requires a gem (e.g. rspec/core/rake_task) that is missing from the Gemfile or in an excluded group, so the file cannot be loaded.
rake run outside the bundle
Invoking rake directly instead of bundle exec rake means the bundle load path is not set up, so even installed gems are not findable.
How to fix it
Run rake through Bundler
bundle exec sets up the load path so the Rakefile’s requires resolve.
bundle exec rake --trace
# --trace shows the full backtrace to the failing requireAdd the missing gem to the Gemfile
If the require is for a gem not in the bundle, declare it in the right group and install.
# Gemfile
group :development, :test do
gem 'rspec'
endHow to prevent it
- Always run rake via bundle exec (or a binstub) in CI.
- Declare every gem the Rakefile requires, in a group that is installed.
- Use --trace to pinpoint the failing require quickly.