2

I am using capistrano to deploy a rails 7.0.4.3 app. When I run cap production deploy the service stops at this step:

deploy:assets:precompile 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile

producing this error

01 rake aborted!
      01 Sprockets::FileNotFound: couldn't find file 'trix/dist/trix' with type 'text/css'
      01 Checked in these paths:
      01   /home/deploy/dynamic_performance/releases/20230530181802/app/assets/config
      01   /home/deploy/dynamic_performance/releases/20230530181802/app/assets/images
      01   /home/deploy/dynamic_performance/releases/20230530181802/app/assets/stylesheets
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/tailwindcss-rails-0.3.3/app/assets/fonts
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/tailwindcss-rails-0.3.3/app/assets/stylesheets
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/actiontext-7.0.4.3/app/assets/javascripts
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/actiontext-7.0.4.3/app/assets/stylesheets
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/actioncable-7.0.4.3/app/assets/javascripts
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/activestorage-7.0.4.3/app/assets/javascripts
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/actionview-7.0.4.3/lib/assets/compiled
      01   /home/deploy/dynamic_performance/shared/bundle/ruby/3.2.0/gems/turbolinks-source-5.2.0/lib/assets/javascripts
.... truncated for brevity

I've read other post which say to run yarn install --check-files and rails action_text:install but that does not help. Action text works fine when I run rails s locally. How do I fix this error and compile my assets properly?

CJG
  • 457
  • 2
  • 17

1 Answers1

2

That happened to me, here is what happens under the hood. After upgrading to Rails 7.0, the task rake assets:precompile does not execute yarn install. That is why Sprockets can't find dependencies in node_modules folder. You can use the following code for this issue.

before "deploy:assets:precompile", "deploy:yarn_install"
namespace :deploy do
  desc "Run rake yarn install"
  task :yarn_install do
    on roles(:web) do
      within release_path do
        execute("cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
      end
    end
  end
end

I guess it is an intended behavior of Rails 7.

titan2gman
  • 408
  • 9