presidentbeef/brakeman · error · NoBrakemanError
Cannot find lib/ directory.
Error message
Cannot find lib/ directory.
What it means
Early in `Brakeman.scan`, the library requires its own `brakeman/scanner` file; if that `require` raises `LoadError`, Brakeman reports `NoBrakemanError` with the misleading message 'Cannot find lib/ directory.' Despite the wording, this is about Brakeman's own library code not being loadable — a broken/partial gem installation or a corrupted Ruby load path — not about your application's `lib/` directory.
Source
Thrown at lib/brakeman.rb:450
return "Brakeman #{current} is not the latest version #{latest_version}"
else
false
end
else
false
end
end
#Run a scan. Generally called from Brakeman.run instead of directly.
def self.scan options
#Load scanner
scanner, tracker = nil
process_step 'Loading scanner' do
begin
require 'brakeman/scanner'
rescue LoadError
raise NoBrakemanError, 'Cannot find lib/ directory.'
end
add_external_checks options
#Start scanning
scanner = Scanner.new options
tracker = scanner.tracker
check_for_missing_checks options[:run_checks], options[:skip_checks], options[:enable_checks]
end
logger.announce "Scanning #{tracker.app_path}"
scanner.process
tracker.run_checks
self.filter_warnings tracker, options
View on GitHub (pinned to 649e678d0a)
Solutions
- Run through bundler with brakeman in the Gemfile: add `gem 'brakeman', require: false` and invoke `bundle exec brakeman`.
- Verify which Ruby and gem brakeman resolves to: `head -1 $(which brakeman)` and `gem which brakeman/scanner`; make sure both point at the same Ruby installation.
- Reinstall the gem: `gem install brakeman` (and `rbenv rehash` / `rvm gems ... ` if applicable).
- If running from a brakeman source checkout, launch it as `bundle exec bin/brakeman` from the checkout root so the local `lib/` is on the load path.
Example fix
# before (system brakeman shim, gem installed under a different Ruby) brakeman . # => Brakeman::NoBrakemanError: Cannot find lib/ directory. # after (bundled, consistent Ruby) bundle add brakeman --skip-install && bundle install && bundle exec brakeman .
Defensive patterns
Strategy: validation
Validate before calling
# Ruby, smoke-test the install before invoking a scan begin require 'brakeman/scanner' rescue LoadError abort 'brakeman gem not loadable under this Ruby — run `bundle install` or `gem install brakeman`.' end Brakeman.run :app_path => app_path
Try / catch
begin Brakeman.run :app_path => app_path rescue Brakeman::NoBrakemanError abort 'Brakeman library not loadable. Fix with `bundle exec brakeman` or reinstall the gem, then retry.' end
Prevention
- Declare brakeman in the Gemfile and always invoke via `bundle exec brakeman` so the gem resolves under the bundle's Ruby.
- In Docker/CI, install the gem in the same image layer and user that runs the scan.
- Verify environment parity before scanning: `head -1 $(which brakeman)` and `gem which brakeman/scanner` must agree.
When it happens
Trigger: `require 'brakeman/scanner'` failing: the brakeman gem is missing from the active Ruby's gem set (rbenv/rvm shim pointing at a different Ruby than the one with the gem installed), a corrupted partial gem install, running a checkout of brakeman's own source via `bin/brakeman` without the library on `$LOAD_PATH`, or a bundler context where brakeman is not in the Gemfile.
Common situations: Multiple Ruby installs (system Ruby vs rbenv/rvm) so `which brakeman` executes a shim whose Ruby lacks the gem; Docker images where `gem install brakeman` ran in a different layer/user than the runtime; running brakeman inside a fork/checkout of brakeman itself; `RUBYOPT`/`RUBYLIB` environment variables clobbering the load path; a Gemfile.lock resolution that dropped brakeman from the bundle.
Related errors
- Comparison file doesn't exist
- Parsing #{path} took too long (> #{@timeout} seconds). Try i
- Cannot specify output format if multiple output files specif
- Invalid GitHub repository format
- Could not find specified check#{missing.length > 1 ? 's' : '
AI-assisted analysis of presidentbeef/brakeman@649e678d0a (2026-08-21).
Data as JSON: /api/errors/d3de9f176f58b2fc.
Report an issue: GitHub.