DEV Community

Lucas Freymund Ehresmann Osik
Lucas Freymund Ehresmann Osik

Posted on

Asset precompile issue during Capistrano deployment process on legacy Rails code

Recently I was using Capistrano (version: 3.17.3) as a deployment tool for a Rails 5.2 application, along with other legacy content, such as JQuery. During the deployment process, the asset pre-compile step returned the error:

Sprockets::FileNotFound: could not find file 'jquery/dist/jquery' with type 'application/javascript'

Investigating the issue, I discovered that Capistrano is not installing my Node dependencies with Yarn (version: 3.6.3), within the production environment during deployment, possibly due to some incompatibility with the current version of Yarn I was using.

I managed to solve the problem by placing a task in "config/deploy.rb" that forces "yarn install" to be executed:

set :stage, :production
set :rails_env, 'production'

namespace :deploy do
    desc 'Install Node.js dependencies'
    task :install_node_dependencies do
        on roles(:app) do
            within release_path do
                execute :yarn, 'install --production' 
            end
        end
    end

    before 'deploy:assets:precompile', 'deploy:install_node_dependencies'
end
Enter fullscreen mode Exit fullscreen mode

Top comments (0)