`require_directory` doesn't work like expected #183

ream88 opened this Issue Sep 5, 2011 · 21 comments


None yet

ream88 commented Sep 5, 2011

Hey guys,

I have following problem with sprockets: http://stackoverflow.com/questions/7312653/sprockets-require-directory-problem


josh commented Sep 6, 2011

./ means in the current directory.

If you want

  *= require_directory ./yahoo

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

josh closed this Sep 6, 2011

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

ream88 commented Sep 6, 2011

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

hadiS commented Sep 7, 2011

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

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.

sorry , type wrong, should be

require_directory ./foo

got require_directory argument must be a relative path

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.

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.

milushov commented Aug 3, 2012

same problem


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

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

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 May 8, 2013


LeEnno commented May 26, 2013


LeEnno commented May 26, 2013

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.

dv commented Apr 6, 2014

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.

👍 @dv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment