Rake "aborted! LoadError: cannot load such file" in CI
A rake task tried to require a file or library that Ruby could not find on the load path. The rake run aborts and prints the missing path, which is the gem or file that was never required through the bundle.
What this error means
A rake step fails with "rake aborted!" followed by "LoadError: cannot load such file -- X" and a backtrace pointing into the Rakefile or a required task file.
rake aborted!
LoadError: cannot load such file -- dotenv/tasks
/home/runner/work/app/app/Rakefile:4:in `require'Common causes
The required gem is not in the active groups
The Rakefile requires a gem that lives in a Gemfile group CI excluded (for example development), so it is not installed for the task.
rake ran without the bundle
rake was invoked without bundle exec, so the bundled load path was not set and the require failed.
How to fix it
Run rake through Bundler
- Invoke the task with bundle exec so the bundle load path is active.
- Ensure the required gem is in a group CI installs.
- Re-run so the require resolves.
bundle exec rake assets:precompileInstall the group the task needs
If the require is in a Rakefile loaded everywhere, do not exclude its group, or move the require behind a group check.
bundle config set --local without ''
bundle installHow to prevent it
- Run rake via bundle exec so the load path is correct.
- Keep gems required at Rakefile load time in installed groups.
- Guard optional requires so excluded groups do not break tasks.