Skip to content
Latchkey

Rails "ActionView::Template::Error: Asset ... is not present" in CI

A template raised while resolving an asset helper because Sprockets could not find the asset. In CI this is usually a missing precompile step or an asset not listed in the precompile allowlist.

What this error means

A view test or request fails with "ActionView::Template::Error" wrapping "Asset application.css was not declared to be precompiled in production" or "is not present in the asset pipeline".

Rails
ActionView::Template::Error:
Asset `application.css` was not declared to be precompiled in production.
Declare it in `config/initializers/assets.rb`.

Diagnose it: Ruby version and platform

Bundler resolves against the Ruby version and the platform recorded in the lockfile. A runner on a different Ruby or a Linux platform missing from Gemfile.lock fails in a way that names a gem rather than the cause.

Terminal
ruby -v && bundle -v
cat .ruby-version 2>/dev/null
bundle platform

# the usual CI-only failure: Linux platform absent from the lockfile
bundle lock --add-platform x86_64-linux
bundle install --jobs 4 --retry 3

Common causes

Assets were not precompiled in CI

The environment expects compiled assets, but no assets:precompile step ran, so the helper cannot resolve the file.

The asset is not in the precompile list

A file outside the default manifest must be added to Rails.application.config.assets.precompile or it is treated as missing.

How to fix it

Precompile assets before rendering

Run the precompile task in the CI job so Sprockets can resolve every referenced asset.

.github/workflows/ci.yml
- run: bin/rails assets:precompile
  env:
    RAILS_ENV: test
    SECRET_KEY_BASE_DUMMY: '1'

Declare non-default assets

Add standalone assets to the precompile list so they are built and resolvable.

config/initializers/assets.rb
# config/initializers/assets.rb
Rails.application.config.assets.precompile += %w[admin.css report.js]

How to prevent it

  • Precompile assets in CI before any view or request test.
  • Keep custom assets in the precompile allowlist.
  • Match asset host and pipeline settings between CI and production.

Frequently asked questions

What causes Rails "ActionView::Template::Error: asset ... is not present" in CI?
There are 2 common causes: assets were not precompiled in ci and the asset is not in the precompile list. The environment expects compiled assets, but no assets:precompile step ran, so the helper cannot resolve the file.
How do I fix Rails "ActionView::Template::Error: asset ... is not present" in CI?
There are 2 fixes depending on which cause you have: precompile assets before rendering and declare non-default assets. Work through them in order, since the first is the most common.
What does Rails "ActionView::Template::Error: asset ... is not present" in CI actually mean?
A view test or request fails with "ActionView::Template::Error" wrapping "Asset application.css was not declared to be precompiled in production" or "is not present in the asset pipeline".
How do I stop Rails "ActionView::Template::Error: asset ... is not present" in CI happening again?
Precompile assets in CI before any view or request test. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card