Newly created Stimulus controllers not loading (possible import maps issue)

I have 2-3 existing Stimulus controller (created previously). These load fine.

Today I created a couple new Stimulus controllers. These are not being linked in <head> and, thus, not loading at all.

In the server log I get this:

Importmap skipped missing path: controllers/full_screen_controller.js
Importmap skipped missing path: controllers/element_closer_controller.js
Importmap skipped missing path: controllers/share_controller.js
Importmap skipped missing path: controllers/xxx_controller.js

That explains why these are not showing up in <head>. But it’s still not clear why these specifically are “missing”.

I think I have narrowed this down to a problem with import maps (and possibly some interaction with the content_security_policy).

I suspect this may have something to do with the content_security_policy in config/initializers/content_security_policy.rb where these are set:

  config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
  config.content_security_policy_nonce_directives = %w(script-src style-src)

But what’s odd is that even when I completely turn off the CSP, it still doesn’t work.

I’m trying to walk through the importmap-rails code starting with javascript_importmap_tags (and trying to find my way down to resolve_asset_path where the warning appears to come from.)

The method javascript_importmap_tags starts with Rails.application.importmap which, when I look in the console, does have all of the Stimulus controllers.

But the new Stimulus controllers are not in the importmap or <head> <link>s by the time everything is fully generated.

Has anyone else run into this?

Is there a cache I’m not aware of?

I figured it out.

For some reason there were pre-compiled assets under public/assets. I’m not sure how or when those were generated. It must have been after I created the previous Stimulus controller and before these new ones. They appeared to take precedence. So the new one were not getting picked up.

I resolved this issue by simply running bin/rails assets:clobber. This clears out public/assets. These pre-compiled assets do not appear to be getting regenerated. I’m not entirely sure how they were before. I have not directly run bin/rails assets:precompile so I’m still a bit confused.