Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


`require_directory` doesn't work like expected #183

haihappen opened this Issue · 21 comments

17 participants

Mario Uher Joshua Peek jacob-carlborg Hadi S. Jerry Shen Alan Rubin Sterling Cobb GetScripted Roma Milushov Jeff Huber Rune Skjoldborg Madsen James Hagerman Ivan Joaquim fmy Enrico Schlag David Verhasselt Paulo L F Casaretto
Joshua Peek

./ means in the current directory.

If you want

  *= require_directory ./yahoo

It would have to be a file in vendor/assets/javascripts.

Joshua Peek josh closed this

I'm having the same issue. I don't see why require_directory and require_tree needs a relative path where require does not. I mean, I can do:

//= require foo

And have foo.js in vendor/assets/javascripts. But the same doesn't work for require_directory or require_tree. Why can't I do like this:

//= require_tree bar

And it will find the bar directory in vendor/assets/javascripts? An alternative would be to have specific requires for the vendor and lib directories. This is the current workaround I'm using:


//= require foo


//= require_tree ./foo
Mario Uher

Thank you @josh, seems I need some kind of proxy file located in my vendor/assets/stylesheets directory. Like a yahoo.css included in my application.css:

 *= require_directory ./yahoo
Hadi S.

I totally agree with @jacob-carlborg and thanks for the workaround.

Jerry Shen

I have the problem too,
I want to require a directory in vendor/assets/javascripts/foo
require ./foo

got require_directory argument must be a relative path


I think this issue should be reopened because several other have the same problem.

Jerry Shen

sorry , type wrong, should be

require_directory ./foo

got require_directory argument must be a relative path

Alan Rubin

Got to the same issue : My use case is that I'm going to configure a load_path at runtime (depending on the plugin I'm using), so in the main file I need to configure "require_directory stores", and stores js files will be added depending on the load_path I have configured.

Please think about reopening and fixing this issue.

Sterling Cobb

I agree, this should not be only relative for require_directory, please consider reopening.


I got this "require_directory argument must be a relative path" issue as well. Solved without proxies by specifying:
*= require_tree ../../../vendor/assets/stylesheets/.
It was not obvious to me, though, as I thought the path should be somehow relative to vendor/assets directory, not the manifest file, hence a lot of trial and error.

Roma Milushov

same problem

James Hagerman

Has this still not been addressed? This is obviously a continuing issue...

James Hagerman

After a bit more research, I understand this issue a bit more:

*= require_directory ./derp
Equates to looking for files in:

While this:
//= require_directory ./derp
Looks in:

So, required_directory does not handle the "vendor" directory tree at all.

This still seems like an issue but whatever...

Ivan Joaquim

It don't work for me too, i think the './' was a reference for all the directories who rails see like 'assets', does not matter where is our assets if is in 'vendor', 'lib' or any directory we have set in our config file.

For me, this is a open issue.

fmy commented


Enrico Schlag


Enrico Schlag

The official Rails way to solve this is a little like @jacob-carlborg suggested and is described here.

In app/assets/javascripts/application.js:

//= require foo

In vendor/assets/javascripts/foo/index.js:

//= require_tree .

As long as the file is called index.js everything will work. All files inside of vendor/assets/javascripts/foo will be included.

Nevertheless I think we have a bug here. require_directory and require_tree should look in vendor/assets directory, just like require does.

David Verhasselt
dv commented

So, @josh you referenced another bug report here, but there still is no explanation why require_directory et al can't work as described here. Is there a technical reason, or is it just out of purity considerations?

To me, and apparently a lot of other people, it seems logical and more intuitive that a require_directory and require_tree should look in all load paths including vendor/assets, exactly like require does. It doesn't make sense, from a UI perspective, that there would be any difference between these two types of directives in where it searches for files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.