railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.87k stars 2.25k forks source link

Sprockets::FileNotFound Error: couldn't find file 'rails_admin/filter-box' #3597

Closed rnevius closed 1 year ago

rnevius commented 1 year ago

Describe the bug

After upgrading from 3.0.0 to 3.1.0, Webpacker is able to compile the front-end, but rails image_tag calls throw the following error:

ActionView::Template::Error (couldn't find file 'rails_admin/filter-box' with type 'application/javascript'
Checked in these paths: 
  /usr/src/app/app/assets/builds
  /usr/src/app/app/assets/config
  /usr/src/app/app/assets/fonts
  /usr/src/app/app/assets/images
  /usr/src/app/app/assets/stylesheets
  /usr/local/bundle/gems/rails_admin-3.1.1/app/assets/javascripts
  /usr/local/bundle/gems/rails_admin-3.1.1/app/assets/stylesheets
  /usr/local/bundle/gems/rails_admin-3.1.1/vendor/assets/fonts
  /usr/local/bundle/gems/rails_admin-3.1.1/vendor/assets/javascripts
  /usr/local/bundle/gems/rails_admin-3.1.1/vendor/assets/stylesheets
  /usr/local/bundle/gems/turbo-rails-1.3.3/app/assets/javascripts
  /usr/local/bundle/gems/nested_form-0.3.2/vendor/assets/javascripts
  /usr/local/bundle/gems/font-awesome-rails-4.7.0.8/app/assets/fonts
  /usr/local/bundle/gems/font-awesome-rails-4.7.0.8/app/assets/stylesheets
  /usr/local/bundle/gems/chartkick-4.2.1/vendor/assets/javascripts
  /usr/local/bundle/gems/rails-assets-bulma-divider-1.0.5/app/assets/javascripts
  /usr/local/bundle/gems/rails-assets-bulma-divider-1.0.5/app/assets/stylesheets
  /usr/local/bundle/gems/bulma-rails-0.9.3/app/assets/stylesheets
  /usr/local/bundle/gems/ahoy_matey-4.1.0/vendor/assets/javascripts
  /usr/local/bundle/gems/actioncable-6.1.7.2/app/assets/javascripts
  /usr/local/bundle/gems/activestorage-6.1.7.2/app/assets/javascripts
  /usr/local/bundle/gems/actionview-6.1.7.2/lib/assets/compiled
  /usr/src/app/app/assets/fonts
  /usr/src/app/node_modules):
     9: 
    10:       .navbar__brand
    11:           = image_tag "logo/layers.svg", class: "navbar__logo"
    12: 
    13:       .navbar__placeholder
    14: 

app/views/projects/_navbar.html.haml:11
app/views/projects/show.html.haml:7
app/controllers/projects_controller.rb:93:in `show'

Reproduction steps

Seems like just upgrading to 3.1 from 3.0 is enough to cause the issue. Re-running the installer doesn't fix anything.

Additional context

mshibuya commented 1 year ago

Could you provide what you have in config/initializers/rails_admin.rb ?

rnevius commented 1 year ago

Sure thing! Here are the contents of config/initializers/rails_admin.rb:

RailsAdmin.config do |config|
  config.asset_source = :webpacker

  config.parent_controller = "::AdminController"

  ## == Devise ==
  config.authenticate_with { warden.authenticate! scope: :user }
  config.current_user_method(&:current_user)

  config.authorize_with do |controller|
    if current_role != "admin"
      redirect_to "/", alert: "Unauthorized"
    end
  end

  config.actions do
    dashboard                     # mandatory
    index                         # mandatory
    new
    export
    bulk_delete
    show
    edit
    delete
    show_in_app
    import

    config.default_hidden_fields[:edit] = [:id, :updated_at]
    config.default_hidden_fields[:show] = [:id]
  end
end
rnevius commented 1 year ago

There's at least one other instance of this happening, but there isn't much context provided: https://stackoverflow.com/questions/75022373/sidekiq-and-rspec-doesnt-work-after-rails-admin-upgrade-to-3-1-1

mshibuya commented 1 year ago

My guess is for some reason the asset rails_admin/application.js is picked up by your app, which is for Sprockets-based setup and not to be used with asset_source = :webpacker.

Could you check following points?

rnevius commented 1 year ago

What do you get if you do grep -r rails_admin app/assets/config app/assets/javascripts in your Rails application's root?

The app/assets/javascripts directory doesn't exist. I'm using webpacker and all javascript assets are packs in app/javascript/packs. There's nothing related to rails admin in the manifest.js file in app/assets/config.

What's the output of Rails.application.config.assets.precompile from Rails console?

irb(main):023:0> Rails.application.config.assets.precompile
=> 
[#<Proc:0x0000ffff8183b838 /usr/local/bundle/gems/sprockets-rails-3.4.2/lib/sprockets/railtie.rb:88 (lambda)>,
 /(?:\/|\\|\A)application\.(css|js)$/,                                                        
 "turbo.js",                                                                                  
 "turbo.min.js",                                                                              
 "turbo.min.js.map",                                                                          
 "rails_admin/application.js",                                                                
 "rails_admin/application.css"]
mshibuya commented 1 year ago

Thanks, config.assets.precompile shouldn't contain rails_admin/application.js and rails_admin/application.css and that's the cause. The question is where they came from. Could you try grep -r rails_admin/application . in the Rails app root?

rnevius commented 1 year ago
❯ grep -r rails_admin/application .                              
Binary file ./tmp/cache/bootsnap/load-path-cache matches
Binary file ./tmp/cache/bootsnap/compile-cache-iseq/a4/5560d61065a40d matches
Binary file ./tmp/cache/bootsnap/compile-cache-iseq/c4/6dd5ecb4a5a2a9 matches
mshibuya commented 1 year ago

Does rails tmp:clear make difference?

rnevius commented 1 year ago

It doesn't 😞

rnevius commented 1 year ago

This was an issue with Sprockets itself. Upgrading from 3.7 -> 4.2 fixes the problem. Apologies for sending you on a futile search.

rnevius commented 1 year ago

More context: https://github.com/rails/sprockets/blob/main/CHANGELOG.md#400beta7

mshibuya commented 1 year ago

Great that you could find the cause! This will also help others who have this issue 👍

drusepth commented 1 year ago

I had this same issue as well. Upgrading Sprockets from 3.7 -> 4.2 also fixed it for me.