skip to content

When moving a Rails 7 app from Sprockets to Propshaft ahead of Rails 8.1, what breaks, and what do you change in the Gemfile, config and stylesheets?

level: seniorimportance: should knowfreq 30%

answer

  1. swap sprockets-rails and sass-rails for propshaft
  2. delete app/assets/config/manifest.js
  3. image_url() becomes url('/...')
  4. require directives are just comments
  5. excluded_paths for compiler inputs

basics

~10 s

Swap sprockets, sprockets-rails and sass-rails for propshaft, delete app/assets/config/manifest.js, rewrite image_url() calls in CSS as url('/...'), and move Sass, require-directive concatenation and minification to a build gem, because Propshaft only digests and serves files.

solid answer

~30 s

In the Gemfile, remove `sprockets`, `sprockets-rails` and `sass-rails`, add `propshaft`, and check `Gemfile.lock` for gems that still pull Sprockets in. Delete `app/assets/config/manifest.js`, drop `config.assets.paths << Rails.root.join("app", "assets")` and any `require "sprockets/railtie"`. Then fix what Propshaft does not do: `*= require_tree` and `//= require` lines are now plain comments, so either link files with `stylesheet_link_tag :app` or build bundles with jsbundling-rails / cssbundling-rails / dartsass-rails into `app/assets/builds`; Sass helpers such as `image_url('hero.jpg')` become `url('/hero.jpg')`; and if the Sass sources stay in `app/assets/stylesheets`, list that folder in `config.assets.excluded_paths` so raw `.scss` is not copied. `config.assets.precompile`, `compile`, `debug` and the compressors become silent shims.

code

ruby · 9 lines
ruby
# Gemfile
# gem "sprockets-rails"   # removed
# gem "sass-rails"        # removed
gem "propshaft"
gem "dartsass-rails"       # Sass now builds into app/assets/builds

# config/initializers/assets.rb
Rails.application.config.assets.excluded_paths <<
  Rails.root.join("app/assets/stylesheets")   # raw .scss stays out of public/assets

go deeper

for a junior

Recall that Propshaft does not compile Sass or merge files, so those jobs need a build gem after the switch.

for a middle

Walk through the concrete steps: Gemfile swap, deleting manifest.js, rewriting image_url() as url('/...'), and excluded_paths for Sass sources.

for a senior

Show how you would de-risk it: a separate deploy before the 8.x upgrade, MissingAssetError caught by rendering layouts in tests, and a diff of public/assets.

for a principal

Judge whether to migrate at all for an app with heavy Sprockets-dependent gems, versus keeping sprockets-rails as a supported legacy pipeline for now.

## Why the move is not a gem swap **Sprockets** was a compiler, a concatenator and a digester in one. **Propshaft** is only the last of those: it finds files on a load path, stamps digests, writes `public/assets/.manifest.json` and serves files in development. Everything an app relied on Sprockets to *transform* has to move somewhere else first, which is why its upgrade guide warns that the migration can be real work. A new Rails 8.1 app gets Propshaft unconditionally; an upgraded app keeps `sprockets-rails` until you remove it, so the move is a step you schedule, not something the upgrade does for you. ## Step by step 1. **Gemfile.** Remove `sprockets`, `sprockets-rails` and `sass-rails`, add `propshaft`, run `bundle install`, and search `Gemfile.lock` for gems that still depend on `sprockets` or `sprockets-rails`; each needs a replacement or an upgrade. 2. **Railties.** If `config/application.rb` requires frameworks individually, remove `require "sprockets/railtie"`. 3. **Load path.** Delete `config.assets.paths << Rails.root.join("app", "assets")`; Propshaft already adds every subfolder of `app/assets`, `lib/assets` and `vendor/assets`. 4. **Manifest.** Delete `app/assets/config/manifest.js`; Propshaft copies every file on its paths, so there is nothing to link. 5. **Stylesheets.** Replace Sass asset helpers with plain CSS: `image_url('hero.jpg')` and `font_url(...)` become `url('/hero.jpg')`. 6. **Layout.** Point `stylesheet_link_tag` at real files: `:app` for every stylesheet under `app/assets`, or the built file a CSS gem produces. ## What breaks, and where it goes | Sprockets feature | After the move | |---|---| | `.scss` compiled on the fly | dartsass-rails, cssbundling-rails or tailwindcss-rails build into `app/assets/builds` | | `*= require_tree .` / `//= require` | ignored comments; use `stylesheet_link_tag :app`, import maps or a bundler | | CoffeeScript, `.js.erb`, `.css.erb` | not evaluated; rewrite as plain JS or CSS, or build with jsbundling-rails | | `css_compressor` / `js_compressor` | no minification; a bundler can minify its own output | | `image_url()` relative to the asset roots | `url()` relative to the CSS file, `/` for the load-path root | | Gems that inject assets through Sprockets | must ship plain files or be replaced | ## Configuration that quietly stops mattering Propshaft defines `config.assets.precompile`, `config.assets.debug`, `config.assets.compile`, `config.assets.css_compressor` and `config.assets.js_compressor` only as **compatibility shims** so old initializers boot. Setting them does nothing. Interviewers like this trap because an initializer full of them suggests a tuning that no longer happens. Two keys are new to use: - `config.assets.excluded_paths` — full paths, such as `Rails.root.join("app/assets/stylesheets")`, removed from the load path. Use it when that folder now holds only Sass sources that dartsass-rails compiles into `app/assets/builds`; otherwise Propshaft would copy every partial into `public/assets`. - `config.assets.integrity_hash_algorithm` — required before `integrity: true` on `stylesheet_link_tag` emits anything, since Propshaft stores SRI hashes in its manifest. ## Behaviour changes worth testing - **Missing assets raise.** `asset_path` for an unknown logical path raises `Propshaft::MissingAssetError`. A template that names an asset Sprockets used to produce on the fly — an `.scss` entry point, say — fails while rendering until a build gem emits that file, so render every layout in a test before deploying. - **Relative CSS URLs.** A stylesheet in a subfolder that wrote `url('hero.jpg')` meaning "from the images root" now resolves beside itself; check development logs for `Unable to resolve` warnings. - **Local precompile freezes development.** Unlike Sprockets, once `public/assets/.manifest.json` exists Propshaft serves the precompiled copies until `bin/rails assets:clobber`. - **Cascade order.** Separate `<link>` tags from `:app` apply in sorted logical-path order instead of the order a `require` list imposed. ## How to stage it - Do the move on Rails 7.x first, as its own deploy, before the 8.x upgrade, so an asset regression is not tangled with framework changes. - Get the CSS build working under `bin/dev` while Sprockets is still present, then remove Sprockets. - Precompile in CI and diff the list of files in `public/assets` against what the old build produced; missing fonts and images show up there before users see them. ## When not to migrate yet Sprockets still works on Rails 8.1 through `sprockets-rails` 3.5; it is legacy, not removed. An app whose admin area depends on gems that inject Sass through Sprockets, or that has hundreds of `.js.erb` files, may be better served by upgrading Rails first and moving the pipeline later, once those dependencies have Propshaft-friendly releases. The judgement turns on how much transformation the app relies on: an app already building JS and CSS with Node tools moves in an afternoon, because Propshaft just digests what the bundlers produce; an app that leans on Sprockets for Sass, ERB and concatenation needs each of those jobs re-homed before the switch.

  • After the migration a layout raises Propshaft::MissingAssetError for admin.css. What do you check first?
    Whether `admin.css` still exists as a file on the load path: under Sprockets it may have been an `.scss` entry point compiled on the fly. Run `bin/rails assets:reveal` to list logical paths; if it is missing, the CSS build gem must emit `admin.css` into `app/assets/builds`, and `bin/dev` or the build step must have run.
  • Why put app/assets/stylesheets in config.assets.excluded_paths rather than deleting it from config.assets.paths in config/application.rb?
    At that point the folder is not on the list yet: Propshaft's own initializer adds every engine's `app/assets`, `lib/assets` and `vendor/assets` subfolders later, then subtracts whatever `excluded_paths` holds. So `excluded_paths`, given full paths such as `Rails.root.join("app/assets/stylesheets")`, is the switch that takes effect.

  • Swapping the gem is enough because Propshaft compiles the existing .scss files
  • Keep manifest.js so Propshaft knows which files to precompile
  • config.assets.css_compressor still minifies CSS after the switch
  • Rails 8 upgrades refuse to boot until Sprockets is removed
  • Propshaft quietly falls back to an undigested path when an asset is missing

Assumes Rails 8.1 and Propshaft 1.3; Propshaft is the default since Rails 8.0 and the only pipeline rails new offers in 8.1, while an app upgraded from 7.x keeps sprockets-rails until it is removed.