Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssetNotPrecompiled on a stylesheet_link_tag call #708

Open
emirkin opened this issue Jun 10, 2021 · 4 comments
Open

AssetNotPrecompiled on a stylesheet_link_tag call #708

emirkin opened this issue Jun 10, 2021 · 4 comments

Comments

@emirkin
Copy link

emirkin commented Jun 10, 2021

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
Copy link
Member

Can you provide an example application that reproduce the issue?

@emirkin
Copy link
Author

emirkin commented Jun 10, 2021

picaboo.zip

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

@emirkin
Copy link
Author

emirkin commented Jun 10, 2021

@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
Copy link
Contributor

ahorek commented Jun 25, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants