15

How do you remove Sprockets from Rails?

I've..

  • removed all the Sprockets Gems.
  • removed all the config.assets.* from initializers, etc..

Still, Rails is looking for Sprockets

/Users/username/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/railtie.rb:105:in block in <class:Railtie>': Expected to find a manifest file in `app/assets/config/manifest.js (Sprockets::Railtie::ManifestNeededError)

......

 Example:
13:58:38 web.1  |   //= link_tree ../images
13:58:38 web.1  |   //= link_directory ../javascripts .js
13:58:38 web.1  |   //= link_directory ../stylesheets .css

How do you actually remove Sprockets?

code_aks
  • 1,972
  • 1
  • 12
  • 28
GN.
  • 8,672
  • 10
  • 61
  • 126
  • What do you mean when you say you've "removed all the Sprockets Gems"? Is it still in your `Gemfile` or `Gemfile.lock`? – Schwern Dec 28 '19 at 22:04
  • I've removed it from Gemfile. Bundled. But it still exisits in Gemfile.lock. `sprockets-rails` – GN. Dec 28 '19 at 22:18
  • You should be able to tell from the `Gemfile.lock` what depends on it. You may also need to do a `bundle update sprockets-rails`. You can also do this in one step with [`bundle remove sprockets-rails`](https://bundler.io/man/bundle-remove.1.html). – Schwern Dec 28 '19 at 22:22
  • 2
    Its nested under `rails (6.0.2.1)`. I've removed it with bundler. It removes it from Gemfile, but it remains in Gemfile.lock – GN. Dec 28 '19 at 22:26
  • did you remove `require "sprockets/railtie"` from `config/application.rb`? – max Dec 28 '19 at 22:42
  • I'm not seeing any refs to sprockets in my app at all. `config.load_defaults 6.0` is the only config in application.rb – GN. Dec 28 '19 at 22:44
  • 3
    Was the app created as a Rails 6 application or migrated? In older Rails apps you might just have [`require "rails/all"`](https://github.com/rails/rails/blob/master/railties/lib/rails/all.rb) while the generated application.rb in new versions will require each railtie explicitly. – max Dec 28 '19 at 22:50
  • Yup. Just caught that. `require 'rails/all'` is the culprit. – GN. Dec 28 '19 at 22:56
  • It was migrated from 5 app. – GN. Dec 28 '19 at 22:56
  • Replaced it with individual requires and it works. If you want to add the answer I'll accept it.. – GN. Dec 28 '19 at 22:58
  • 2
    There doesn't seem to be a way to remove it from the Gemfile.lock as it's a runtime dependency of the the rails gem. bundler complains – Anthony Mar 18 '20 at 19:26

1 Answers1

28

To completely remove sprockets from a Rails project:

Remove:

# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'

from Gemfile then run bundle install.

Replace:

require 'rails/all'

with:

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
# require "sprockets/railtie"
require "rails/test_unit/railtie"

in config/application.rb file.

Remove:

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true

# Suppress logger output for asset requests.
config.assets.quiet = true

from config/environments/development.rb file.

Remove:

# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

from config/environments/production.rb file.

Remove config/initializers/assets.rb file.

You can also remove app/assets folder but it is not necessary because you may need it later if you changed your mind.

MibraDev
  • 1,029
  • 11
  • 17
  • 2
    Hi, I'm Using Rails 5.2.4 and I did exactly as you said. However, sprockets-rails is still a dependency for rails in my Gemfile.lock and it is used at runtime. I want to remove it to save memory. How can I do that ? – Henry Boisgibault Nov 23 '20 at 20:23
  • You'd also want to remove `gem 'sprockets-rails'` in case you have it in your Gemfile – Ackshaey Singh May 24 '21 at 00:25
  • I add all this (rails 6.1.3) and still get: `Expected to find a manifest file in app/assets/config/manifest.js (Sprockets::Railtie::ManifestNeededError)` – rigyt Jun 02 '21 at 14:03
  • @rigyt seems like the sprocket https://github.com/rails/sprockets-rails/blob/1a0cf7a4572d0ee728d3dda2013d3305a77932f1/lib/sprockets/railtie.rb#L71-L81 is still running. most likely you haven't remove ```require "sprockets/railtie"``` in application.rb – AirWick219 Jul 16 '21 at 04:54
  • 1
    Even if you do all of this, there is still a dependency on sprockets-rails from rails. I am using rails version 6.1.4.6 and it requires sprockets-rails. I tried removing every dependency of sprockets in Gemfile.lock, but then the application will not load. – Aleksandr Movsesyan Feb 28 '22 at 22:39