CircleCI + Rails 7 + Yarn + assets:precompile - `yarn: not found`

I am using Circle CI to run RSpec tests on a Rails project. I’m new to CircleCI, so I’m piecing together a build script from examples.

My tests are failing because application.css is not in the asset pipeline. Here is the exact error:

ActionView::Template::Error:
  The asset "application.css" is not present in the asset pipeline.

I figured this is because the assets are not being precompiled. So I added bundle exec rails assets:precompile to my config.yml. I also included cimg/node:19.2.0 to provide yarn.

However, when the build runs, CircleCI reports that the yarn command cannot be found. Here is the exact error:

#!/bin/bash -eo pipefail
bundle exec rake assets:precompile
sh: 1: yarn: not found
rake aborted!
jsbundling-rails: Command build failed, ensure yarn is installed and `yarn build` runs without errors
/home/circleci/my_project/vendor/bundle/ruby/3.1.0/gems/jsbundling-rails-1.0.3/lib/tasks/jsbundling/build.rake:5:in `block (2 levels) in <main>'
/home/circleci/my_project/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'
/home/circleci/.rubygems/bin/bundle:25:in `load'
/home/circleci/.rubygems/bin/bundle:25:in `<main>'
Tasks: TOP => assets:precompile => javascript:build
(See full trace by running task with --trace)

Exited with code exit status 1
CircleCI received exit code 1

My understanding is that yarn should be provided by the cimg/node:19.2.0, so I’m not sure why it cannot be found.

I’ve posted my config.yml as a Gist here: CircleCI 2.1 Config for Rails 7 Project with Yarn · GitHub

  • Line 22 is where I added cimg/node:19.2.0
  • Lines 53-55 is where I added bundle exec assets:precompile

It might be important to note that my tests were running fine (and passing) until I started testing view related code.