rails / sprockets

Rack-based asset packaging system
MIT License
954 stars 790 forks source link

AssetNotPrecompiled on a stylesheet_link_tag call #708

Open emirkin opened 3 years ago

emirkin commented 3 years ago

I get AssetNotPrecompiled from the following code: = stylesheet_link_tag 'common/login' (in a file called index.haml).

Here's how my assets are configured:

precompile_files = Dir.glob('app/assets/**/*.*')
Rails.application.config.assets.precompile = ['manifest.js'] + precompile_files
Rails.application.config.assets.register_engine '.haml', Tilt::HamlTemplate

My app/assets/config/manifest.js looks like this:

  //= link_tree ../images
  //= link_tree ../javascripts
  //= link_tree ../stylesheets (this is where 'common/login.scss' resides)
  //= link_tree ../lib

System configuration

    sprockets (4.0.2)
      concurrent-ruby (~> 1.0)
      rack (> 1, < 3)

    sprockets-rails (3.2.2)
      actionpack (>= 4.0)
      activesupport (>= 4.0)
      sprockets (>= 3.0.0)

    haml (5.2.1)
      temple (>= 0.8.0)
      tilt

    haml-rails (2.0.1)
      actionpack (>= 5.1)
      activesupport (>= 5.1)
      haml (>= 4.0.6, < 6.0)
      html2haml (>= 1.0.1)
      railties (>= 5.1)

    sass-rails (6.0.0)
      sassc-rails (~> 2.1, >= 2.1.1)
rafaelfranca commented 3 years ago

Can you provide an example application that reproduce the issue?

emirkin commented 3 years ago

picaboo.zip

Here you go. Open http://localhost:3000/login

emirkin commented 3 years ago

@rafaelfranca , the reason exception is thrown is that sprockets-rails-3.2.2:lib/sprockets/railtie.rb

    def asset_precompiled?(logical_path)
      if precompiled_assets.include?(logical_path)
        true
      elsif !config.cache_classes
        # Check to see if precompile list has been updated
        precompiled_assets(true).include?(logical_path)
      else
        false
      end
    end

returns false.

My file is listed in the precompiled array but with a ".scss" extension (common/login.scss), whereas the incoming logical path is ".css" (common/login.css). That is why it cannot find it. Assuming the logical path is correct, I am not sure why the precompiled array holds it as scss (I was expecting the precompilation to yield a css). Any ideas?

ahorek commented 3 years ago

btw: you already have common/login.scss included in your layout by application.css.

stylesheet_link_tag 'asset.scss' used to work with the previous sprockets version. I'm not sure if it was internationally dropped or not, but now you need a css file for an endpoint and require all scss files into it. This way it works as expected.