Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Expected to find a manifest file" error with assets disabled #444

Closed
delner opened this issue Oct 9, 2019 · 26 comments
Closed

"Expected to find a manifest file" error with assets disabled #444

delner opened this issue Oct 9, 2019 · 26 comments

Comments

@delner
Copy link

delner commented Oct 9, 2019

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.

@rafaelfranca
Copy link
Member

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

@delner
Copy link
Author

delner commented Oct 10, 2019

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'.

@rafaelfranca
Copy link
Member

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.

@delner
Copy link
Author

delner commented Oct 11, 2019

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?

@rafaelfranca
Copy link
Member

That is for disabling compilation of assets. That doesn't disable the sprockets-rails to be loaded or executed.

@matthewmath
Copy link

Just curious, the path is sprockets 3.2.1, why is using_sprockets4? now returning true and dropping into the required manifest code?

@rafaelfranca
Copy link
Member

sprockets is different of sprockets-rails. The path is sprockets-rails-3.2.1

@denys-husiev
Copy link

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 :)

Marahin added a commit to visualitypl/jsonapi_parameters that referenced this issue Oct 21, 2019
Marahin added a commit to visualitypl/jsonapi_parameters that referenced this issue Oct 21, 2019
Marahin added a commit to visualitypl/jsonapi_parameters that referenced this issue Oct 21, 2019
@hugoh59
Copy link

hugoh59 commented Oct 23, 2019

How do you solve this error?

@andreynering
Copy link

I could solve it by running:

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

vill added a commit to vill/bemer that referenced this issue Nov 3, 2019
muryoimpl added a commit to muryoimpl/buoys that referenced this issue Nov 7, 2019
muryoimpl pushed a commit to muryoimpl/buoys that referenced this issue Nov 7, 2019
* 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/loofah/releases)
- [Changelog](https://github.com/flavorjones/loofah/blob/master/CHANGELOG.md)
- [Commits](flavorjones/loofah@v2.2.3...v2.3.1)

Signed-off-by: dependabot[bot] <support@github.com>

* Fix error: Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)

ref: rails/sprockets-rails#444
sanemat pushed a commit to moneyforward/sample_accounts_api that referenced this issue Nov 8, 2019
mkdir -p app/assets/config && echo '{}' > app/assets/config/manifest.js

rails/sprockets-rails#444 (comment)
russellballestrini added a commit to remind101/slashdeploy that referenced this issue Nov 13, 2019
# 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 && echo '{}' > app/assets/config/manifest.js
#
# rails/sprockets-rails#444
#
#	new file:   app/assets/config/manifest.js

# This is the commit message #3:

fix sprocket 4 and sass -> rails-sassc

	modified:   Gemfile
	modified:   Gemfile.lock
	modified:   app/assets/config/manifest.js
	modified:   config/initializers/assets.rb
ssinghi added a commit to kreeti/kt-paperclip that referenced this issue Dec 6, 2019
ssinghi added a commit to kreeti/kt-paperclip that referenced this issue Dec 6, 2019
* bind sprockets to v3.7.2 because of rails/sprockets-rails#444, rails 4.2 by default does require 'rails/all'

* add ruby 2.5 and 2.6
@joelcahalan
Copy link

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.

@sobrinho
Copy link

Got bitten by this one more time today.

pierre added a commit to killbill/killbill-avatax-ui that referenced this issue Jun 17, 2020
See rails/sprockets-rails#444.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
gaganawhad added a commit to desiringgod/wakes that referenced this issue Jun 30, 2020
Later versions of sprokets which are included with rails require setting
up a manifest file for assets

See: rails/sprockets-rails#444
gaganawhad added a commit to desiringgod/wakes that referenced this issue Jul 1, 2020
Later versions of sprokets which are included with rails require setting
up a manifest file for assets

See: rails/sprockets-rails#444
gaganawhad added a commit to desiringgod/wakes that referenced this issue Jul 1, 2020
Later versions of sprokets which are included with rails require setting
up a manifest file for assets

See: rails/sprockets-rails#444
gaganawhad added a commit to desiringgod/wakes that referenced this issue Jul 2, 2020
Later versions of sprokets which are included with rails require setting
up a manifest file for assets

See: rails/sprockets-rails#444
gaganawhad added a commit to desiringgod/wakes that referenced this issue Jul 2, 2020
Later versions of sprokets which are included with rails require setting
up a manifest file for assets

See: rails/sprockets-rails#444
@swapnilchincholkar
Copy link

Faced the same issue with API only app with rails(v 6.0.3.3), ruby(v 2.7.1). Required to do both of the following,

  1. Uncommented require "sprockets/railtie" from config/application.rb
  2. And creating empty manifest file as said by @andreynering

@mayankdedhia
Copy link

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.

Just doing this worked for my API only app

@gingerlime
Copy link

gingerlime commented Oct 9, 2020

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.

mpw5 added a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Dec 14, 2020
Updating Rails to v6.1.0 causes sprockets to be updated to v4.0.2 as a
dependency. That version expects app/assets/config/manifest.js to be
present, which it is not since switching to webpacker. This causes an
error and prevents the server starting.

This commit adds sprockets to the gemfile and pins it as < v4.0 to
prevent any unexpected updates in future.

See rails/sprockets-rails#444 for discussion
of the issue.
@omarsotillo
Copy link

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

@omarsotillo
Copy link

Also recommended by @ahorek here (did not try myself)

just change

//= require applicationtest.sass
to

//= require applicationtest

stephenrichards pushed a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Dec 28, 2020
Updating Rails to v6.1.0 causes sprockets to be updated to v4.0.2 as a
dependency. That version expects app/assets/config/manifest.js to be
present, which it is not since switching to webpacker. This causes an
error and prevents the server starting.

This commit adds sprockets to the gemfile and pins it as < v4.0 to
prevent any unexpected updates in future.

See rails/sprockets-rails#444 for discussion
of the issue.
Obsiye pushed a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Jan 1, 2021
Updating Rails to v6.1.0 causes sprockets to be updated to v4.0.2 as a
dependency. That version expects app/assets/config/manifest.js to be
present, which it is not since switching to webpacker. This causes an
error and prevents the server starting.

This commit adds sprockets to the gemfile and pins it as < v4.0 to
prevent any unexpected updates in future.

See rails/sprockets-rails#444 for discussion
of the issue.
marshall-strong added a commit to marshall-strong/yenius that referenced this issue Jan 3, 2021
Obsiye pushed a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Jan 4, 2021
Updating Rails to v6.1.0 causes sprockets to be updated to v4.0.2 as a
dependency. That version expects app/assets/config/manifest.js to be
present, which it is not since switching to webpacker. This causes an
error and prevents the server starting.

This commit adds sprockets to the gemfile and pins it as < v4.0 to
prevent any unexpected updates in future.

See rails/sprockets-rails#444 for discussion
of the issue.
@yonyossef
Copy link

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

Hi, can anyone tell me if the manifest.js file link is hard coded in sprockets, or it can be changed to a different location?
Can I change it from app/assets/config/manifest.js to lib/assets?
Thx

Obsiye pushed a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Jan 8, 2021
Updating Rails to v6.1.0 causes sprockets to be updated to v4.0.2 as a
dependency. That version expects app/assets/config/manifest.js to be
present, which it is not since switching to webpacker. This causes an
error and prevents the server starting.

This commit adds sprockets to the gemfile and pins it as < v4.0 to
prevent any unexpected updates in future.

See rails/sprockets-rails#444 for discussion
of the issue.
Obsiye pushed a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Jan 15, 2021
Updating Rails to v6.1.0 causes sprockets to be updated to v4.0.2 as a
dependency. That version expects app/assets/config/manifest.js to be
present, which it is not since switching to webpacker. This causes an
error and prevents the server starting.

This commit adds sprockets to the gemfile and pins it as < v4.0 to
prevent any unexpected updates in future.

See rails/sprockets-rails#444 for discussion
of the issue.
Obsiye pushed a commit to ministryofjustice/laa-apply-for-legal-aid that referenced this issue Jan 18, 2021
Updating Rails to v6.1.0 causes sprockets to be updated to v4.0.2 as a
dependency. That version expects app/assets/config/manifest.js to be
present, which it is not since switching to webpacker. This causes an
error and prevents the server starting.

This commit adds sprockets to the gemfile and pins it as < v4.0 to
prevent any unexpected updates in future.

See rails/sprockets-rails#444 for discussion
of the issue.
@kevinmtrowbridge
Copy link

This monkeypatch will allow the behavior to be changed (perhaps introducing other problems ... use only after thinking about the tradeoffs):

module Sprockets
  class Railtie < ::Rails::Railtie
    initializer :set_default_precompile_manifest_optional, after: :set_default_precompile do |app|
      # Find original method here: https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L103
      p "sprockets_monkeypatch_make_manifest_optional.rb"
      app.config.assets.precompile += %w( manifest.js )
    end
    # https://dev.to/st0012/how-to-replace-a-rails-initializer-30n0
    initializers.reject! { |i| i.name == :set_default_precompile }
  end
end

purfectliterature added a commit to Coursemology/coursemology2 that referenced this issue Dec 14, 2023
acts_as_tenant v1.0.0 bumps sprockets to v4. In v4, there are some
changes to how sprockets bundle assets, and they require a `manifest.js`
to tell sprockets how to bundle the app's assets. We are not bundling
assets, but for some reasons, sprockets has no way of opting out of
this. See rails/sprockets-rails#444
purfectliterature added a commit to Coursemology/coursemology2 that referenced this issue Dec 14, 2023
acts_as_tenant v1.0.0 bumps sprockets to v4. In v4, there are some
changes to how sprockets bundle assets, and they require a `manifest.js`
to tell sprockets how to bundle the app's assets. We are not bundling
assets, but for some reasons, sprockets has no way of opting out of
this. See rails/sprockets-rails#444
bivanalhar pushed a commit to Coursemology/coursemology2 that referenced this issue Dec 21, 2023
acts_as_tenant v1.0.0 bumps sprockets to v4. In v4, there are some
changes to how sprockets bundle assets, and they require a `manifest.js`
to tell sprockets how to bundle the app's assets. We are not bundling
assets, but for some reasons, sprockets has no way of opting out of
this. See rails/sprockets-rails#444
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests