Reputation: 11
I am migrating an app from sprockets-rails
and jsbundling-rails
to propshaft
and importmap-rails
, and am running into an interesting, but befuddling issue.
I have a file located at app/javascript/meetings.js
. I have this line in my config/importmap.rb
file:
...
pin "main", preload: false
pin "meetings", preload: false
...
In main.js, I have the following:
import "meetings"
I am loading that on select layouts in the head, like so:
<%= javascript_importmap_tags %>
<%= javascript_import_module_tag "main" %>
That seemed to all be working just fine, until I made a change to meetings.js
. I had previously been using an undeclared variable like so:
show_recs = ...;
That triggered an error, prompting me that show_recs
was undefined, so I updated the line to the following:
let show_recs = ...;
When I reloaded the page, the same error was present. (And it was referring me to the line I had just changed in meetings.js
.) Upon further investigation, I discovered that changes to meetings.js
were not triggering a change to the fingerprint, and neither were changes to main.js
.
What makes this even stranger (to me) is that I then decided to run rake assets:precompile
, and when I looked in public/assets/meetings-[new-fingerprint].js
, I found the old (unchanged) line still present, even though I now have no file in my source that has that line! It's as if propshaft
(or perhaps importmap-rails
?) is looking at some cached version of that file somewhere to build public/assets
, but it's nowhere in my project.
(And yes, I have saved the changes to the files in question, so it's not something quite that simple.)
Any ideas?
What I tried
As mentioned above, I made a change to a .js file, expecting propshaft
/importmap-rails
to serve the newly updated version of that resource. When it did not, I tried running rake assets:precompile
to force a rebuild of the assets, which somehow produced output that did not match any of the source files.
What I expected
I expected the output to match the changes I'd made to the source files. I certainly did not expect it to populate public/assets
with code that no longer exists anywhere in my project.
Upvotes: 1
Views: 248
Reputation: 77
I have come across this too in my development environment.
I can resolve it by stopping the local service, running:
rake assets:clobber
Then restarting the server.
In production, its fine, as I run:
bundle exec rake assets:precompile RAILS_ENV=production
as part of my deployment script.
Any work arounds for the development environment?
Upvotes: 0