Why does Rails fails to boot with "Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)"?
Asked Answered
L

4

77

After bundle update my Rails app fails to boot with:

Expected to find a manifest file in `app/assets/config/manifest.js` (Sprockets::Railtie::ManifestNeededError)
Lauree answered 11/10, 2019 at 10:45 Comment(0)
R
125

What's happening?

Looks like you've upgraded sprockets. The later version(s) of sprockets require what's called a manifest.js file. You don't have one. You need to create one, and add in a few "directives".

Why do I need to do this?

In the old version of sprockets, big assumptions were made about what assets to bundle/concatenate** - this is what sprockets does btw.

"Sprockets, please"

  • bundle everything in folder abc together
  • bundle AND concatenate everything in folder xyz
  • keep admin.js separate.

Easy Steps To Solve the Problem:

  1. Create the manifest.js file

    $ mkdir -p app/assets/config 
    $ touch app/assets/config/manifest.js
     (not the root rails directory)
    
  2. Then copy and paste the following into the manifest.js file you just created:

    //= link_tree ../images
    //= link_directory ../javascripts .js
    //= link_directory ../stylesheets .css
    

What are "Directives"?

Those commenty things //= are called "directives".

If you haven't done so, pls review the sprockets documentation and save yourself some headaches. Small example below:

Let's translate the //= link_directory ../javascripts .js directive:

"grab every js file in the javascripts directory, concatenate them, and keep them as SEPARATE javascript files i.e. no bundling." If you want bundling, use a different directive.

Set up your layouts template

You should also have a javascript_include_tag, which is typically placed in your application.html.erb file. If you have other files js files that are separately bundled, don't forget to add them to application.html.erb e.g.:

<%= javascript_include_tag "application", "addOtherFiles", "here", "etc", "data-turbo-track": "reload", defer: true %>
  1. If you have a precompile array in your app/config/environments/production.rb folder (see below for an example) then perhaps you should move them over to your manifest.js if they are not already accessed above.

    config.assets.precompile = ["admin.js", "admin.css"]

Presumably you will want your admin.js javascript file separate from your application.js file. No problem, just tell sprockets to keep them separate:

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
//= link "admin.js"
  1. Lastly, if you are using webpacker, you might want to decide what you want handled by the asset pipeline and what you want handled by webpacker. i.e. remove the link_directory to the javascripts file according to your own particular use cases.

Reference: read here for further details re: manifest.js. file

Source: Thanks to Richard Schneeman's blog - see here for more information..


Footnotes and Primers

  • Concatenating? Normally JavaScript has a lot of white space. To speed things up, you can transform your JS code so that it has no white spaces, so it can be uploaded quickly - that's concatenating.
  • And bundling? Not as important as it was anymore, but you can combine multiple JS files into one single file, and send that over to the browser). The latest changes are a step in the right direction: now you have to tell sprockets explicitly, what files you want bundled and/or concatenated: this is done in your manifest.js file e.g.:

EDIT: if things are confusing / not clear: complain loudly! How can I fix if you keep mum? everyone benefits by these improvements.

Review answered 14/10, 2019 at 4:30 Comment(2)
Even though I have the file it stills says, Expected to find a manifest file in app/assets/config/manifest.jsMuddlehead
Try restarting server. or spring stop. otherwise, i have no idea. please feel free to edit this answer when any of you solve it.Review
L
30

A new major version of sprockets was recently released which is not compatible with the previous version.

Either perform the steps needed to upgrade or pin to version 3.x in Gemfile

gem 'sprockets', '~>3.0'
Lauree answered 11/10, 2019 at 10:45 Comment(0)
H
11

Based on the answer here you may be able to solve this with:

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

And if you need more details, the answer in this thread helpfully points to the Guide to upgrading from Sprockets 3.x to 4.x

Heartless answered 28/2, 2020 at 2:37 Comment(1)
A bit of clarification: This solution is for an API-only rails app. The app that I needed this info for is, so this solution worked well for me. But if someone was actually expecting rails to compile their assets for them, this wouldn't work.Chamkis
K
0

As suggested by link http://www.redmine.org/boards/2/topics/58169, it is a known issue. See #32223 and sprockets 4.0.0 breaks Redmine 3.4.11 with Ruby <2.5.0.

I just reproduced this issue with redmine 3.4.4, but found everything is ok with Redmine 3.4.12.

wget http://www.redmine.org/releases/redmine-3.4.12.tar.gz

Ken answered 27/11, 2019 at 1:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.