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
- Add spec/app/assets/config/manifest.js Per sprockets issue: https://github.com/rails/sprockets-rails/issues/444 — committed to visualitypl/jsonapi_parameters by Marahin 5 years ago
- Fix per sprockets issue: https://github.com/rails/sprockets-rails/issues/444 — committed to visualitypl/jsonapi_parameters by Marahin 5 years ago
- Fix per sprockets issue: https://github.com/rails/sprockets-rails/issues/444 (#22) — committed to visualitypl/jsonapi_parameters by Marahin 5 years ago
- Add `manifest.js` file See: https://github.com/rails/sprockets-rails/issues/444 — committed to vill/bemer by vill 5 years ago
- Fix error: Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError) ref: https://github.com/rails/sprockets-rails/issues/444 — committed to muryoimpl/buoys by muryoimpl 5 years ago
- Bump loofah from 2.2.3 to 2.3.1 (#57) * Bump loofah from 2.2.3 to 2.3.1 Bumps [loofah](https://github.com/flavorjones/loofah) from 2.2.3 to 2.3.1. - [Release notes](https://github.com/flavorjones... — committed to muryoimpl/buoys by dependabot[bot] 5 years ago
- chore(deps): sprockets4 mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js https://github.com/rails/sprockets-rails/issues/444#issuecomment-548526846 — committed to moneyforward/sample_accounts_api by deleted user 5 years ago
- # This is a combination of 3 commits. # This is the 1st commit message: upgrade gems to fix CVEs with loofa # The commit message #2 will be skipped: # fix build error # # mkdir -p app/assets/config... — committed to remind101/slashdeploy by russellballestrini 5 years ago
- Add manifest.js file to new assets config folder to fix sprockets issue https://github.com/rails/sprockets-rails/issues/444 — committed to uktrade/export-opportunities by WillTaylor22 5 years ago
- bind sprockets to v3.7.2 because of https://github.com/rails/sprockets-rails/issues/444, rails 4.2 by default does require 'rails/all' — committed to kreeti/kt-paperclip by ssinghi 5 years ago
- bind sprockets to v3.7.2 for fixing cucumber specs (#7) * bind sprockets to v3.7.2 because of https://github.com/rails/sprockets-rails/issues/444, rails 4.2 by default does require 'rails/all' * a... — committed to kreeti/kt-paperclip by ssinghi 5 years ago
- Fix sprockets breaking (fix from https://github.com/rails/sprockets-rails/issues/444) — committed to indentlabs/notebook by drusepth 5 years ago
- Upgrade from Rails 6.0.0 to 6.0.2.1 Also needed to create an empty manifest file due to Sprockets 4: % mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js As noted in rails/spro... — committed to bluz71/platters by bluz71 4 years ago
- Fixes build error See: https://github.com/rails/sprockets-rails/issues/444 — committed to Karimit/gatherin by deleted user 5 years ago
- Bundle update, fix sprockets js not bundling. (From https://github.com/rails/sprockets-rails/issues/444). — committed to ProjectVinyl/ProjectVinyl by Sollace 4 years ago
- Attempt fix per https://github.com/rails/sprockets-rails/issues/444 — committed to FrontPages/backend by jaypinho 4 years ago
- CMR-6267 Removes sprockets/railtie https://github.com/rails/sprockets-rails/issues/444 — committed to nasa/cmr-csw by daniel-zamora 4 years ago
- CMR-6267 Removes sprockets/railtie https://github.com/rails/sprockets-rails/issues/444 — committed to nasa/cmr-csw by daniel-zamora 4 years ago
- Added manifest js file. https://github.com/rails/sprockets-rails/issues/444 — committed to bigbinary/wheel by ashiksp 4 years ago
- Added manifest js file. https://github.com/rails/sprockets-rails/issues/444 — committed to bigbinary/wheel by ashiksp 4 years ago
I could solve it by running:
The proper way to fix this is stop using
require 'rails/all'
and not loadsprockets/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) becausesprockets-rails
doesn’t check whether its actually enabled or not seems like a bad experience for Rails users whogem 'rails'
.An alternative approach to avoiding this issue would be to lock
sprockets-rails
to pre 4.x by explicitly adding to yourGemfile
: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 ofrequire 'rails/all'
) is the only way to disable Sprockets, then what is the purpose ofconfig.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:
sassc-rails
or find alternativetmp/assets
folderapp/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:
require "rails/all"
require "sprockets/railtie"
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 missingI 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:My
Gemfile
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.