"require_tree argument must be a directory" rails 3.1.1 precompile assets
Asked Answered
E

4

29

I've been round and round here with trying to get the assets to pre-compile on my production server (straightforward ubuntu install with ruby 1.9.2 and Rails 3.1.1, and tried 3.1.2RC with the new sprockets 2.10 as well).

"require_tree argument must be a directory". I've seen other issues related to this on stack but the situation isn't exactly the same and none of the proposed solutions have helped – like create a stub file in the sub folder, then reference only relatively at that point. No luck.

And to top it off, of course this works perfectly on all development machines (mac's but with identical configs, even matching gem for gem), in production env.

Here is my /app/assets/javascript/application.js:

//= require ../../views/app/manifest
//= require_self

Not much to it. Basically just pointing to the real manifest file for the app area (yeah, not exactly boxed vanilla Rails but...)

Here is my stub manifest in my views/admin (/views/app/manifest.coffee.js):

# = require ./app
# = require_tree ./models
# = require_directory ./views <- or using require_directory, either would work fine.

Like I said, in dev env, no issues at all. The asset pipeline compiles on the fly and everything is great. Running, rake assets:precompile on the dev machine, no issues either.

I send it up to the production machine and run the exact same code and I get:

require_tree argument must be a directory

There has to be some tiny tiny difference here that I'm just not seeing. Any help would be much appreciated!

Epigraphy answered 17/11, 2011 at 17:57 Comment(4)
you really should move them assets where they belongs to and not put them in the app/view directoryRatcliffe
Its a bit more complicated then shown in this simplified example. The views are tightly tied to the assets and make more sense being physically located.Epigraphy
Could it be that manifest.coffee.js should be manifest.js.coffee?Inauspicious
Add .gitkeep files (or .gitignore files to your empty dirs.Appositive
D
85

I ran into this exact same issue you described. My production server was Heroku (cedar stack). In my case the issue was that one of my:

require_tree ./mobile

Was pointing to a legitimate directory, but this directory had no files. On dev it didn't matter but something about the production setup was resulting in the error, “require_tree argument must be a directory”.

Hopefully that helps.

Display answered 18/12, 2011 at 8:38 Comment(5)
So I just lost 2 hours to this and hopefully it will help someone in the future. If nothing is in the folder heroku may not create it. (you'll have to put at least a .gitkeep in there if you still want it)Levitus
This is an issue with git rather than ruby or rails. Git does not create a directory if there are no files in it. Check your repo, I bet there are no empty dirs in there.Doomsday
Just had this problem with the Backbone Gem for Rails. Thanks for providing this solution! Everything works now :)Thorlay
Yeah just putting a file in those empty directories fixed the issue for me. Even just empty files.Nicoline
The good way is to put a blank file in the empty directory called ".gitkeep"Housebreaker
A
18

require_tree must be given an existing folder, but git doesn't store empty folders, therefore when you deploy on heroku, those empty folders doesn't exist.

one trick is to add an empty .keep file to the folders you want to keep.

Analemma answered 10/5, 2014 at 20:46 Comment(1)
This is the real reason the empty directory does not exist in production because its not in git.Articulate
H
1

For me, it worked to manually create an (empty) folder shared/vendor/javascript.

Hippel answered 6/10, 2022 at 5:28 Comment(0)
L
0

Spent some time debugging a related issue. Turns out, a JavaScript error was preventing the whole directory from loading. So I'd recommend focusing on resolving any console errors first.

For other require_tree issues, I'd recommend also reviewing the sprockets documentation, ie. https://github.com/rails/sprockets#sprockets-directives

Larkspur answered 31/7 at 3:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.