Rails: Asset not precompiled
A referenced asset (CSS, JS, image) was not included in the precompiled asset list for production.
Quick fix
Read the commands before running them. Anything that restarts a service, deletes data or changes permissions should be tried on a non-production system first.
# Precompile assets
RAILS_ENV=production bundle exec rails assets:precompile
# Add custom assets to precompile list in config/initializers/assets.rb
Rails.application.config.assets.precompile += %w( admin.js admin.css )
# Clear old assets
bundle exec rails assets:clobber
How to diagnose Ruby errors
Ruby errors are dominated by Bundler and gem resolution, native extension compilation (which needs system headers Ruby cannot install for you), and in Rails by the pending-migration and asset-precompilation guards. Those guards are deliberate safety checks, so the fix is to satisfy them rather than to disable them.
If the quick fix above does not resolve it, work through these steps. They apply to this whole class of error, not just to this one message, which is usually what saves the time.
- Run
bundle installwith verbose output and read which gem fails and why. Native extension failures name the missing header in the mkmf log. - Check the mkmf log path the error prints. It contains the actual compiler error, which the Bundler summary truncates.
- For Rails migration errors, run
rails db:migrate:statusto see exactly which migrations the database has recorded. - For asset errors in production, confirm
rails assets:precompileran during deployment and that the manifest is present inpublic/assets. - Verify the Ruby version matches
.ruby-versionand the Gemfile. Version managers silently switch, producing gem-not-found errors for gems that are installed elsewhere.
Tools worth reaching for
bundle install --verboserails db:migrate:statusgem envrbenv/rvm version checkbundle exec
Authoritative references
Primary documentation for this error, worth reading before applying any fix in production.
Related Ruby errors
- Bundler: Could not find gemBundler cannot locate the specified gem in any of the configured sources (e.g., RubyGems).
- Encoding::InvalidByteSequenceErrorA string contains bytes that are invalid for the expected encoding (e.g., invalid UTF-8 bytes).
- LoadError: cannot load such fileRuby cannot find the required file or gem. The gem may not be installed, or the require path…
- Rails: ActionController::InvalidAuthenticityTokenThe CSRF token in the request did not match the one in the session. Rails keeps the session…
- Rails: No route matchesThe requested URL does not match any route defined in config/routes.rb.
- Rails: PendingMigrationErrorDatabase schema migrations have not been applied to the database.
- Ruby: can't modify frozen StringThe string is frozen, either by a `# frozen_string_literal: true` magic comment, by Ruby's…
- Ruby: Failed to build gem native extensionA gem with C extensions failed to compile because system libraries or development headers are…
Browse other categories
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Python 35Imports, virtual environments, encoding, concurrency and dependency conflicts.
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
Something missing or wrong?
This entry is maintained by hand. If the fix is out of date, incomplete, or you have a better one, email a correction and it will be reviewed.