Skip to content
Latchkey

Rails "assets:precompile" Fails in CI

rails assets:precompile failed while compiling the asset bundle. The usual causes are a missing JavaScript runtime/Node, an asset Sprockets cannot find, or the task booting the app environment when required secrets are absent.

What this error means

CI fails at the assets:precompile step with a Sprockets "asset was not declared" / "couldn’t find file", an ExecJS runtime error, or an app-boot error (missing ENV/secret) raised while loading the environment to precompile.

rake output
rake aborted!
Sprockets::Rails::Helper::AssetNotFound: The asset "application.js" is not
present in the asset pipeline.

# or
Could not find a JavaScript runtime. (ExecJS::RuntimeUnavailable)

Common causes

No JS runtime / Node for asset compilation

Asset compilation (Sprockets uglifier, or a JS bundler) needs Node or another JS runtime. On a runner without it, precompile fails with ExecJS::RuntimeUnavailable.

Asset not found or app boot needs secrets

A referenced asset is missing/misnamed, or precompile loads the full environment which fails because a required ENV var or secret (SECRET_KEY_BASE, a database URL) is absent in CI.

How to fix it

Install Node and the JS runtime

.github/workflows/ci.yml
- uses: actions/setup-node@v4
  with:
    node-version: '20'
- run: bundle exec rails assets:precompile

Provide the env precompile needs

Supply a dummy SECRET_KEY_BASE and avoid initializing services not needed for asset compilation.

Terminal
SECRET_KEY_BASE=dummy RAILS_ENV=production \
  bundle exec rails assets:precompile

How to prevent it

  • Install Node/yarn in CI before assets:precompile.
  • Provide a dummy SECRET_KEY_BASE so the environment boots for precompile.
  • Keep referenced asset names in sync with files in the pipeline.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →