require_tree argument must be a directory in a Rails 5 upgraded app

I finally figured it out. So because I am doing the upgrade, RailsDiff didn't tell me that I was missing something.

So the error message wasn't incorrect, however, what I forgot to do was to create an empty directory.

In my app/assets/javascripts/cable.js, I had the following:

//= require_tree ./channels

However, I forgot to actually create that folder.

So to fix this, all I had to do was create an empty folder within app/assets/javascripts called channels. Also, because git ignores empty directories, within that newly created folder, I also had to create an empty file called .keep.

So once I did the following, everything worked like a charm:

  • Create folder: app/assets/javascripts/channels
  • Create empty file within that folder: app/assets/javascripts/channels/.keep

Everything works perfectly now.


Faced a similar, but not the same issue. During upgrade of Rails from 5.2.3 to 5.2.4.1

$ rails s returned:

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

Ok, followed the instructions, created manifest.js with the above content, then

$ rails s returned:

Sprockets::ArgumentError at / link_tree argument must be a directory

Fix:

create empty .keep file in a new images folder (which was possibly deleted at some point in the past without any immediate consequences):

app/assets/images/.keep


The problem occurs when using rails new appname --skip-keeps flag - it still tries to require non-existing files and generally is a mistake on Rails team side.

This is just a different approach to the described problem, the main solution works perfectly;

  1. Open app/assets/javascripts/cable.js
  2. Remove autogenerated //= require_tree ./channels, from line 6

Keep your codebase as small as possible, someone skipped the .keeps for a reason.