I am trying to locally precompile assets (for production) and I get an error.
My steps:
- bundle exec rake assets:clobber --trace (to remove public/assets so I perform a clean compile)
- bundle exec rake assets:precompile RAILS_ENV=production --trace (to compile assets ready to upload to GitHub/Heroku)
I am using: Rails (5.2.2), Ruby (2.6.6), Bundler (2.4.4), Windows (10)
What happens A lot of my .js / .css / .jpg / .png files appear to precompile fine but then it always gives the error when it reaches this glyphicons-halflings-regular file. (Actually 24-hrs ago it tripped up on a .png file - I'm not sure what changed since then - I think I updated the bundler version and now it fails on a different file)
The error message:
Errno::ENOENT: No such file or directory @ rb_sysopen - C:/Users/..../...../public/assets/flatty/bootstrap/glyphicons-halflings-regular-5ff7c239555476e939e86d457bb78424b945b733b2c23791d9807c2357259d43.eot.103323240.10692.178366
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:278:in `initialize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:278:in `open'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:278:in `atomic_write'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sprockets-3.7.2/lib/sprockets/asset.rb:165:in `write_to'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:210:in `block (2 levels) in compile'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `block in synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/ivar.rb:169:in `safe_execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/future.rb:55:in `block in execute'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:363:in `run_task'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `block (3 levels) in create_worker'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `loop'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `block (2 levels) in create_worker'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `catch'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/concurrent-ruby-1.1.8/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block in create_worker'
Tasks: TOP => assets:precompile
Questions:
Any ideas? I know a lot of my gems are on old versions, but this precompile used to work for me and I do not know what has changed. Could it be because some gems or ruby or bundler or something are using older versions (but they used to work?)
After trying many different ideas from other threads (e.g. removing hyphens in file and folder names, removing '.' etc.) I discovered that the problem for me was the fact the local path to the file was too long.
If my path to the C:/Users//Documents/.../.../.../public/assets/.... .png was 240 characters it did not work. If the path was 216 characters the precompile worked fine.
So, simply by cloning the database into a local folder with a short filename reduced the lengths of these paths and the precompile worked.
Perhaps in the future I will need to shorten the folder names within my app, or reduce the depth of the path to the app on my hard drive.
Perhaps there is even a way of allowing long pathnames to files within an app but I could not find such a setting.