Fix Sprockets::FileNotFound: couldn't find file 'application.css' with type 'text/css' in Rails
This error occurs when the Rails asset pipeline cannot locate a referenced asset file. It usually means the file was deleted, renamed, or the manifest is misconfigured. Check your app/assets/stylesheets directory for the file and verify your application.css manifest directives point to existing files.
Reading the Stack Trace
Here's what each line means:
- sprockets (4.2.1) lib/sprockets/resolve.rb:28:in `resolve': Sprockets is trying to locate application.css in the asset load paths and failing.
- sprockets-rails (3.4.2) lib/sprockets/rails/helper.rb:375:in `resolve_asset_path': The Rails Sprockets helper is attempting to resolve the path for the stylesheet_link_tag.
- app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__render': The layout template at line 8 calls stylesheet_link_tag which triggers the asset lookup.
Common Causes
1. Missing application.css manifest
The app/assets/stylesheets/application.css file was deleted or never created.
<!-- app/views/layouts/application.html.erb -->
<%= stylesheet_link_tag 'application', media: 'all' %>
<!-- But app/assets/stylesheets/application.css does not exist -->
2. Incorrect manifest directives
The manifest file references stylesheets that do not exist in the asset paths.
/*
*= require nonexistent_framework
*= require_tree .
*= require_self
*/
3. Asset not in load path
The asset exists but is in a directory not included in the Rails asset load paths.
# File is at vendor/custom/styles.css but vendor/custom is not in asset paths
# config/initializers/assets.rb does not include the path
Rails.application.config.assets.paths << Rails.root.join('vendor', 'custom') # missing
The Fix
Create or restore the application.css manifest file with correct directives. The require_tree directive includes all stylesheets in the directory and require_self includes styles defined in the manifest itself.
<!-- app/views/layouts/application.html.erb -->
<%= stylesheet_link_tag 'application', media: 'all' %>
<!-- application.css is missing or has bad directives -->
/* app/assets/stylesheets/application.css */
/*
*= require_tree .
*= require_self
*/
Testing the Fix
require 'rails_helper'
RSpec.describe 'Application layout', type: :request do
it 'renders the layout with stylesheets' do
get root_path
expect(response).to have_http_status(:ok)
expect(response.body).to include('stylesheet')
end
it 'does not raise asset errors' do
expect { get root_path }.not_to raise_error
end
end
Run your tests:
bundle exec rspec spec/requests/layout_spec.rb
Pushing Through CI/CD
git checkout -b fix/rails-asset-pipeline,git add app/assets/stylesheets/application.css,git commit -m "fix: restore application.css manifest for asset pipeline",git push origin fix/rails-asset-pipeline
Your CI config should look something like this:
name: CI
on:
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
ports: ['5432:5432']
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- run: bin/rails db:setup
- run: bin/rails assets:precompile
- run: bundle exec rspec
The Full Manual Process: 18 Steps
Here's every step you just went through to fix this one bug:
- Notice the error alert or see it in your monitoring tool
- Open the error dashboard and read the stack trace
- Identify the file and line number from the stack trace
- Open your IDE and navigate to the file
- Read the surrounding code to understand context
- Reproduce the error locally
- Identify the root cause
- Write the fix
- Run the test suite locally
- Fix any failing tests
- Write new tests covering the edge case
- Run the full test suite again
- Create a new git branch
- Commit and push your changes
- Open a pull request
- Wait for code review
- Merge and deploy to production
- Monitor production to confirm the error is resolved
Total time: 30-60 minutes. For one bug.
Or Let bugstack Fix It in Under 2 minutes
Every step above? bugstack does it automatically.
Step 1: Install the SDK
gem install bugstack
Step 2: Initialize
require 'bugstack'
Bugstack.init(api_key: ENV['BUGSTACK_API_KEY'])
Step 3: There is no step 3.
bugstack handles everything from here:
- Captures the stack trace and request context
- Pulls the relevant source files from your GitHub repo
- Analyzes the error and understands the code context
- Generates a minimal, verified fix
- Runs your existing test suite
- Pushes through your CI/CD pipeline
- Deploys to production (or opens a PR for review)
Time from error to fix deployed: Under 2 minutes.
Human involvement: zero.
Try bugstack Free →No credit card. 5-minute setup. Cancel anytime.
Deploying the Fix (Manual Path)
- Verify the application.css manifest file exists and has valid directives.
- Run bin/rails assets:precompile to confirm assets compile successfully.
- Run the test suite.
- Open a pull request with the fix.
- Merge and verify assets load correctly in staging.
Frequently Asked Questions
BugStack runs the fix through your existing test suite, generates additional edge-case tests, and validates that no other components are affected before marking it safe to deploy.
BugStack never pushes directly to production. Every fix goes through a pull request with full CI checks, so your team can review it before merging.
New Rails 7+ apps default to Propshaft or importmaps. Sprockets is still supported but Propshaft is simpler. If starting fresh, consider Propshaft with cssbundling-rails.
Add the path to config.assets.paths in config/initializers/assets.rb. For example: Rails.application.config.assets.paths << Rails.root.join('vendor', 'custom').