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

Intermittent AssetNotPrecompiledError #514

Open
EmilioCristalli opened this issue Dec 12, 2022 · 4 comments
Open

Intermittent AssetNotPrecompiledError #514

EmilioCristalli opened this issue Dec 12, 2022 · 4 comments

Comments

@EmilioCristalli
Copy link

We are seeing the Sprockets::Rails::Helper::AssetNotPrecompiledError error, but it doesn't happen all the time, and haven't been able to reproduce it. Sorry this issue is going to sound weird :(, but we are not sure what's causing it, or if it's a problem with our config or something in sprockets/sprockets-rails, so would appreciate any help.

We have a Rails application which includes an engine (named admin). The engine has a Sprockets manifest (admin_manifest, which is appended to the main app's app.config.assets.precompile), and the manifest links a couple css and js directories and trees (which resolve, among other things, to the engine's admin/application.css). Then in the engine's layouts/application.html.erb we do <%= stylesheet_link_tag "admin/application", media: "all" %>, which works fine most of the time (both in development and production), but sometimes it raises a Sprockets::Rails::Helper::AssetNotPrecompiledError error. In production the error persists until we rotate the server (using the same code), but in staging it works correctly after we reload the page.

We are not precompiling assets in production, but we have config.assets.compile enabled, so I wouldn't expect it to cause this error (and if we did precompile, i guess this same problem could happen when running rake assets:precompile so the precompilation would miss some files).

It's like for some reason the app.config.assets.precompile is missing the admin_manifest sometimes, or the admin_manifest is missing parts of its content (we have seen this error both with the admin/application.css, and with other js files, which are included in the application layout after the css, so we assume the css was correctly precompiled in those cases)

Relevant configs:

# main app
config.cache_classes = true
config.assets.compile = true
# engine
initializer "admin.assets.precompile" do |app|
  app.config.assets.precompile += %w[admin_manifest]
end

Gem versions:
rails: 7.0.3.1
sprockets-rails: 3.4.2
sprockets: 4.1.1

Stacktrace:

[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:372 :in `raise_unless_precompiled_asset`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:338 :in `digest_path`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:326 :in `asset_path`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:103 :in `block in resolve_asset_path`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:243 :in `block in resolve_asset`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:242 :in `each`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:242 :in `detect`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:242 :in `resolve_asset`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:102 :in `resolve_asset_path`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:80 :in `compute_asset_path`
[GEM_ROOT]/gems/actionview-7.0.3.1/lib/action_view/helpers/asset_url_helper.rb:203 :in `asset_path`
[GEM_ROOT]/gems/actionview-7.0.3.1/lib/action_view/helpers/asset_url_helper.rb:348 :in `stylesheet_path`
[GEM_ROOT]/gems/actionview-7.0.3.1/lib/action_view/helpers/asset_tag_helper.rb:180 :in `block in stylesheet_link_tag`
[GEM_ROOT]/gems/actionview-7.0.3.1/lib/action_view/helpers/asset_tag_helper.rb:179 :in `map`
[GEM_ROOT]/gems/actionview-7.0.3.1/lib/action_view/helpers/asset_tag_helper.rb:179 :in `stylesheet_link_tag`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:186 :in `block in stylesheet_link_tag`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:184 :in `map`
[GEM_ROOT]/gems/sprockets-rails-3.4.2/lib/sprockets/rails/helper.rb:184 :in `stylesheet_link_tag`
@derekharmel
Copy link

@EmilioCristalli Did you end up finding a solution to this problem? This all sounds extremely similar to a problem I'm having.

@EmilioCristalli
Copy link
Author

nope 😞
we just disabled this check as a workaround
app.config.assets.check_precompiled_asset = false

@derekharmel
Copy link

@EmilioCristalli Ah, bummer, but good to know. Thanks for the response!

@solerman
Copy link

solerman commented Dec 5, 2024

We started having this issue after upgrading to rails 7. We have assets.compile disabled and yet it appears at random

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