ruby-on-rails Capistrano无法在预编译资产时找到操作文本css文件

klh5stk1  于 2023-06-07  发布在  Ruby
关注(0)|答案(1)|浏览(171)

我正在使用capistrano部署一个rails 7.0.4.3应用。当我运行cap production deploy时,服务在此步骤停止:
deploy:assets:precompile 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
产生这个错误

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

我读过其他帖子说运行yarn install --check-filesrails action_text:install,但这没有帮助。当我在本地运行rails s时,操作文本工作正常。如何修复此错误并正确编译资产?

mspsb9vt

mspsb9vt1#

发生在我身上的事情,这就是引擎盖下发生的事情。升级到Rails 7.0后,任务rake assets:precompile不会执行yarn install。这就是为什么Sprockets在node_modules文件夹中找不到依赖项的原因。您可以使用以下代码解决此问题。

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

我想这是Rails 7的预期行为。

相关问题