sprockets-rails: "Expected to find a manifest file" error with assets disabled

With the release of Sprockets 4.0 and the requirement of a manifest.js file, we’re seeing an error similar to #443 with sprockets-rails 3.2.1 where our test suite is producing this error:

/usr/local/bundle/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)
But did not, please create this file and use it to link any assets that need
to be rendered by your app:

Example:
  //= link_tree ../images
  //= link_directory ../javascripts .js
  //= link_directory ../stylesheets .css
and restart your server

We load the standard require 'rails/all' in our test suite (which loads sprockets 4.0 by default), but we have no interest in using Sprockets or the asset pipeline within it.

If we disable Sprockets with config.assets.enabled = false in our application, we expect that we shouldn’t need to have a manifest.js file. However, merely having require 'sprockets/railtie' anywhere in your application will force this check to occur unconditionally, regardless of if you’ve disabled the the application pipeline:

https://github.com/rails/sprockets-rails/blob/v3.2.1/lib/sprockets/railtie.rb#L103-L110

initializer :set_default_precompile do |app|
  if using_sprockets4?
    raise ManifestNeededError unless ::Rails.root.join("app/assets/config/manifest.js").exist?
    app.config.assets.precompile += %w( manifest.js )
  else
    app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
  end
end

I would suggest changing this check to be based conditionally on whether assets are enabled or not, so users are not forced to completely remove sprocket-rails to disable it.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 22
  • Comments: 26 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I could solve it by running:

mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js

The proper way to fix this is stop using require 'rails/all' and not load sprockets/rails in your application.

I have this error just because I need to require 'sprockets/railtie' for using graphiql-rails gem. And to fix it, I should add manifest.js file to my rails api project. Seems a little weird 😃

This is shockingly un-empathetic from the Rails team. Look at the number of linked issues this has generated. I have 3-4 test Rails apps in my test suites, every one broke when I upgraded rails in my Gemfile. My apps were generated years ago with rails new. Can we not have better fallback behavior?

The way Rails let you opt-out components is by requiring individual railties. Railties are added once a year, you don’t need a lot of work to add require statements once a year. There is no other option, sorry.

This is not a good option for us; we need all the default Rails components other than Sprockets, and to have to update our require '*/railtie' statements every time Rails adds new components (e.g. ActionText, ActionMailbox) because sprockets-rails doesn’t check whether its actually enabled or not seems like a bad experience for Rails users who gem 'rails'.

An alternative approach to avoiding this issue would be to lock sprockets-rails to pre 4.x by explicitly adding to your Gemfile:

gem "sprockets", "<4"

Judging by the gemspec, Rails 6.0 is still compatible with both sprockets 2.x and 3.x.

If preventing require 'sprockets/railtie' (from being loaded as a part of require 'rails/all') is the only way to disable Sprockets, then what is the purpose of config.assets.enabled = false?

I know this is closed but I found kind of the issue at least for me ( I was upgrading from 5.2 to 6.0 and swap into webpacker) !

After digging into it it was related with sassc rails. It is using sprockets under the hood

My approach:

  • Remove sassc-rails or find alternative
  • Remove all references to assets
  • Remove tmp/assets folder
  • Remove app/assets

Maybe it works for some of you 😃

cc @gingerlime @mayankdedhia @swapnilchincholkar

sorry for another “me too”, but I’m really confused why this happens even for a rails app that doesn’t use sprockets any more. We:

  • removed the gem (sprockets / sprockets-rails are both removed from our Gemfile)
  • remove require "rails/all"
  • commented out require "sprockets/railtie"
  • removed our manifest.json since we no longer use it

Normally rails runs fine, but when we run, e.g. bundle exec rake db:test:prepare we get this error because the manifest.json is missing

I understand the workaround with an empty json file, but this still means that some process is running / checking this file, when it shouldn’t if sprockets is disabled. Right?

EDIT: it seems to happen after we upgraded rails. So even though we don’t have sprockets/sprockets-rails in our Gemfile, it’s installed as a dependency, and then we get this issue because there’s no manifest.json file. Using the workaround seems ok for now, but rather strange.

I had to pin an API only rails app to sprockets less than 4. Despite not requiring sprockets in application.rb it was still somehow being loaded and causing an error.

Never mind found it: https://github.com/rails/rails/blob/5-1-stable/railties/lib/rails/all.rb

(replace 5-1) with your version

For Rails api only:

In file: config/application.rb

Uncomment: require 'sprockets/railtie'

Create app/assets/config/manifest.js and add this:

//= link graphiql/rails/application.css
//= link graphiql/rails/application.js

My Gemfile

...
gem 'graphql', '~> 1.10'

group :development do
  ...
  gem 'graphiql-rails', '~> 1.7'
end

So, what is the cause of this error? I didn’t find this message before 2019, so there were some change that let this error happen.