BetterErrors/better_errors · error · LoadError

The `sassc` gem is required when developing the `better_erro

Error message

The `sassc` gem is required when developing the `better_errors` gem. If you're using a release of `better_errors`, the compiled CSS is missing from the released gem

What it means

better_errors renders its error page from SCSS, and ships a precompiled CSS file inside released gems so end projects never need a Sass compiler. ErrorPageStyle.compiled_css first tries require "sassc" to compile the SCSS on the fly (the development path); when that require fails with LoadError, the gem re-raises this LoadError explaining the two possible root causes: you are developing better_errors locally without sassc in the bundle, or you are using a release where the compiled CSS file is missing from the gem package. In both cases the real problem is that the prebuilt stylesheet is absent and the on-the-fly compiler dependency is not installed.

Source

Thrown at lib/better_errors/error_page_style.rb:8

module BetterErrors
  # @private
  module ErrorPageStyle
    def self.compiled_css(for_deployment = false)
      begin
        require "sassc"
      rescue LoadError
        raise LoadError, "The `sassc` gem is required when developing the `better_errors` gem. "\
          "If you're using a release of `better_errors`, the compiled CSS is missing from the released gem"
        # If you arrived here because sassc is not in your project's Gemfile,
        # the issue here is that the release of the better_errors gem
        # is supposed to contain the compiled CSS, but that file is missing from the release.
        # So better_errors is trying to build the CSS on the fly, which requires the sassc gem.
        #
        # If you're developing the better_errors gem locally, and you're running a project
        # that does not have sassc in its bundle, run `rake style:build` in the better_errors
        # project to compile the CSS file.
      end

      style_dir = File.expand_path("style", File.dirname(__FILE__))
      style_file = "#{style_dir}/main.scss"

      engine = SassC::Engine.new(
        File.read(style_file),
        filename: style_file,
        style: for_deployment ? :compressed : :expanded,

View on GitHub (pinned to fde3b7025d)

Solutions

  1. If you are using better_errors as a dependency (not hacking on it): switch to an official release from RubyGems (gem "better_errors", "~> 2.10" and bundle install) — releases ship the compiled CSS and never need sassc.
  2. If you are developing better_errors locally: add sassc to the development group of the gem's Gemfile and run bundle install.
  3. Alternatively, as a better_errors developer run `rake style:build` in the better_errors checkout to compile the CSS once, so the sassc require path is never taken.
  4. If the error came from a git-sourced or locally-built gem, rebuild/reinstall the gem after the CSS build step so the packaged gem contains the compiled stylesheet.
  5. Verify the fix: `ruby -e "require 'sassc'"` should succeed (dev setup), or confirm the compiled CSS file exists under lib/better_errors/style/ (release setup).

Example fix

# Gemfile (better_errors development checkout)
# before
group :development do
  gem "better_errors", github: "BetterErrors/better_errors"
end

# after (option A - use a release with precompiled CSS)
group :development do
  gem "better_errors", "~> 2.10"
end

# after (option B - actually developing the gem, in better_errors' own Gemfile)
gem "development_deps" # ensure dev group installed, then in the gem repo:
#   bundle install        # pulls in sassc
#   rake style:build      # or precompile the CSS once
Defensive patterns

Strategy: try-catch

Validate before calling

def better_errors_css_available?
  # Released gems ship precompiled CSS; check before touching sassc.
  style_dir = File.expand_path("style", Gem.loaded_specs["better_errors"]&.full_gem_path.to_s)
  require "better_errors"
  dir = File.join(File.dirname(Gem.loaded_specs["better_errors"].full_gem_path), "lib", "better_errors", "style")
  Dir[File.join(dir, "**", "*.css")].any? || gem_available?("sassc")
end

def gem_available?(name)
  !Gem.loaded_specs[name].nil? || Gem::Specification.find_by_name(name)
rescue Gem::LoadError
  false
end

Try / catch

begin
  css = BetterErrors::ErrorPageStyle.compiled_css
rescue LoadError => e
  if e.message.include?("sassc")
    # Fall back: use a released better_errors gem with precompiled CSS,
    # or install sassc (`gem install sassc` / add to Gemfile) and retry.
    raise unless ENV["CI"].nil? # decide policy: hard-fail vs degrade
  else
    raise
  end
end

Prevention

When it happens

Trigger: Calling BetterErrors::ErrorPageStyle.compiled_css (directly or by rendering a better_errors error page) in an environment where (a) lib/better_errors/style/*.css precompiled output is absent — typically a git checkout or a broken/edge gem build — and (b) the sassc gem is not in the bundle, so the require "sassc" fallback fails. Commonly hit by running specs or a Rails app against a git-sourced gem (gem "better_errors", github: ...), or after a release was packaged without running the CSS build step.

Common situations: Pointing the Gemfile at the better_errors GitHub repo instead of a released rubygems version; forking/developing the gem and running tests or a host app without the dev dependencies installed (bundle install with --without development); using an old or malformed gem package whose compiled CSS was excluded from the .gem; CI caches that strip generated files. Note sassc is a native extension, so even adding it can fail on systems without a C toolchain, which pushes users toward using precompiled releases instead.

Related errors


AI-assisted analysis of BetterErrors/better_errors@fde3b7025d (2026-08-21). Data as JSON: /api/errors/9a1e3420f93ca533. Report an issue: GitHub.