rake aborted! LoadError during a Rake task in CI
A Rake task aborted because a require at the top of the Rakefile or a task file could not load a file or gem. The task never ran; loading the task definitions failed first.
What this error means
A rake step prints "rake aborted!" followed by a LoadError naming the file or gem, with a Rakefile/task backtrace. Common when a task requires a gem not in the bundle or a moved file.
rspec
rake aborted!
LoadError: cannot load such file -- dotenv/tasks
/app/Rakefile:4:in `require'Common causes
Required gem not in the bundle
The Rakefile requires a gem (or one of its tasks files) that is not installed in the CI groups.
Not run through Bundler
rake was invoked without bundle exec, so the bundle was not set up and the require missed.
Moved or missing task file
A require_relative in the Rakefile points at a file that was renamed or not committed.
How to fix it
Bundle the dependency and run via Bundler
- Add the required gem to a group CI installs, then bundle install.
- Invoke tasks with bundle exec rake (or bin/rake).
- Fix any require_relative paths that point at moved/missing files.
Terminal
bundle exec rake db:seedHow to prevent it
- Run rake through bundle exec or a binstub.
- Keep Rakefile requires inside groups CI installs.
- Verify the Rakefile loads on a clean checkout.
Related guides
rails assets:precompile failed (Sprockets/Webpacker) in CIFix "rails assets:precompile" failing in CI under Sprockets or Webpacker - a missing asset, JS runtime, manif…
LoadError: cannot load such file in CIFix "LoadError: cannot load such file -- X" from a require in CI - the required path or gem is not on the loa…
"bundle exec: command not found" for a gem binary in CIFix "bundler: command not found: X" / "could not find executable" when running bundle exec in CI - the gem pr…