{"record":{"id":"d3de9f176f58b2fc","repo":"presidentbeef/brakeman","slug":"cannot-find-lib-directory","errorCode":null,"errorMessage":"Cannot find lib/ directory.","messagePattern":"Cannot find lib/ directory\\.","errorType":"exception","errorClass":"NoBrakemanError","httpStatus":null,"severity":"error","filePath":"lib/brakeman.rb","lineNumber":450,"sourceCode":"        return \"Brakeman #{current} is not the latest version #{latest_version}\"\n      else\n        false\n      end\n    else\n      false\n    end\n  end\n\n  #Run a scan. Generally called from Brakeman.run instead of directly.\n  def self.scan options\n    #Load scanner\n    scanner, tracker = nil\n\n    process_step 'Loading scanner' do\n      begin\n        require 'brakeman/scanner'\n      rescue LoadError\n        raise NoBrakemanError, 'Cannot find lib/ directory.'\n      end\n\n      add_external_checks options\n\n      #Start scanning\n      scanner = Scanner.new options\n      tracker = scanner.tracker\n\n      check_for_missing_checks options[:run_checks], options[:skip_checks], options[:enable_checks]\n    end\n\n    logger.announce \"Scanning #{tracker.app_path}\"\n    scanner.process\n\n    tracker.run_checks\n\n    self.filter_warnings tracker, options\n","sourceCodeStart":432,"sourceCodeEnd":468,"githubUrl":"https://github.com/presidentbeef/brakeman/blob/649e678d0a46bda0e7c35874fa7af5d16e19b4f1/lib/brakeman.rb#L432-L468","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"# before (system brakeman shim, gem installed under a different Ruby)\nbrakeman .   # => Brakeman::NoBrakemanError: Cannot find lib/ directory.\n\n# after (bundled, consistent Ruby)\nbundle add brakeman --skip-install && bundle install && bundle exec brakeman .","handlingStrategy":"validation","validationCode":"# Ruby, smoke-test the install before invoking a scan\nbegin\n  require 'brakeman/scanner'\nrescue LoadError\n  abort 'brakeman gem not loadable under this Ruby — run `bundle install` or `gem install brakeman`.'\nend\nBrakeman.run :app_path => app_path","typeGuard":null,"tryCatchPattern":"begin\n  Brakeman.run :app_path => app_path\nrescue Brakeman::NoBrakemanError\n  abort 'Brakeman library not loadable. Fix with `bundle exec brakeman` or reinstall the gem, then retry.'\nend","preventionTips":["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."],"tags":["brakeman","loaderror","installation","bundler","rubygems","load-path"],"backgroundTag":"ruby-gem-loaderror","analyzedSha":"649e678d0a46bda0e7c35874fa7af5d16e19b4f1","analyzedAt":"2026-08-21T18:43:10.938Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}