Webpacker: New webpacker:clean task raises 'No such file or directory' error

Created on 20 Nov 2019  路  6Comments  路  Source: rails/webpacker

Hi,

you guys added recently a new task webpacker:clean which doesn't work for us. Unfortunately we can't prevent this task either because you add it to assets:clean without giving an option to disable it. Would be great if you could add this.

The error is:

Errno::ENOENT: No such file or directory @ apply2files - /var/local/kenhub/kenhub.d/1126/public/packs/application-975ab57e9c1b40f7ec06.js
/var/local/kenhub/kenhub.d/1126/vendor/bundle/ruby/2.5.0/gems/webpacker-4.2.0/lib/webpacker/commands.rb:21:in `delete'
/var/local/kenhub/kenhub.d/1126/vendor/bundle/ruby/2.5.0/gems/webpacker-4.2.0/lib/webpacker/commands.rb:21:in `block in clean'
/var/local/kenhub/kenhub.d/1126/vendor/bundle/ruby/2.5.0/gems/webpacker-4.2.0/lib/webpacker/commands.rb:21:in `each'
/var/local/kenhub/kenhub.d/1126/vendor/bundle/ruby/2.5.0/gems/webpacker-4.2.0/lib/webpacker/commands.rb:21:in `clean'
/var/local/kenhub/kenhub.d/1126/vendor/bundle/ruby/2.5.0/gems/webpacker-4.2.0/lib/webpacker.rb:27:in `clean'
/var/local/kenhub/kenhub.d/1126/vendor/bundle/ruby/2.5.0/gems/webpacker-4.2.0/lib/tasks/webpacker/clean.rake:6:in `block (2 levels) in <top (required)>'
/var/local/kenhub/kenhub.d/1126/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/usr/bin/bundle:23:in `load'
/usr/bin/bundle:23:in `<main>'

We can see in public/packs that these files exist before

application-975ab57e9c1b40f7ec06.js
application-975ab57e9c1b40f7ec06.js.gz
application-975ab57e9c1b40f7ec06.js.map
application-975ab57e9c1b40f7ec06.js.map.gz

but then something in webpacker:clean removes

application-975ab57e9c1b40f7ec06.js
application-975ab57e9c1b40f7ec06.js.gz

and then also complains that thay don't exist anymore.

Most helpful comment

Also have the same issue. I did a bit of debug and it's basically occurring because of gz compressed assets. The code in this method https://github.com/LuanGB/webpacker/blob/0c7a9f750ddf3a4fd9a6ad9f91331c80b15c20fd/lib/webpacker/commands.rb#L8 matches finds the original and compressed js file However the ext only pickups up .js As such it tries to delete the js file twice rather than delete the .js and delete .js.gz

All 6 comments

Also have the same issue. I did a bit of debug and it's basically occurring because of gz compressed assets. The code in this method https://github.com/LuanGB/webpacker/blob/0c7a9f750ddf3a4fd9a6ad9f91331c80b15c20fd/lib/webpacker/commands.rb#L8 matches finds the original and compressed js file However the ext only pickups up .js As such it tries to delete the js file twice rather than delete the .js and delete .js.gz

I'm encountering this consistently on our CI and Heroku, the only solution is to clear the whole cache.

Issue can recreated easily:

  1. run bin/rails assets:clobber
  2. run bin/rails assets:precompile && assets:clean
  3. make some random changes like adding console.log to js files
  4. repeat steps 2 and 3 at least 6 times (or however many versions you keep)

EDIT: recreate instructions

This solution worked for us, will be great if you can test this patch https://github.com/rails/webpacker/pull/2382

@tachyons your patch worked great for me.

Looking at it, I wonder if ignoring the Errno::ENOENT errors from File.delete would also make sense. Ideally it would always receive the right files, but there's also no reason to bail so loudly in a "clean" task if a file has already been removed.

I was still running into this error due to missing files, so created a follow up PR that ignores missing file errors: https://github.com/rails/webpacker/pull/2384

@aleksejleonov Sorry, You mean you are still getting missing file error after applying my patch ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FrankFang picture FrankFang  路  3Comments

iChip picture iChip  路  3Comments

ankitrg picture ankitrg  路  3Comments

itay-grudev picture itay-grudev  路  3Comments

Eearslya picture Eearslya  路  3Comments