Skip to content

Intermittent AssetNotPrecompiledError #514

Open
@EmilioCristalli

Description

@EmilioCristalli

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions