DEV Community

Lucas Freymund Ehresmann Osik
Lucas Freymund Ehresmann Osik

Posted on

2 2 2 2 2

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs