Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

FileNotFound followed by CircularDependency #133

Closed
beverlycodes opened this issue Jul 24, 2011 · 5 comments
Closed

FileNotFound followed by CircularDependency #133

beverlycodes opened this issue Jul 24, 2011 · 5 comments
Labels

Comments

@beverlycodes
Copy link

Using v2.0.0.beta.11 with Rails 3.0

I have my javascripts in the following folder structure:

  • app/
    • javascripts/
      • application.js
    • views/
      • staff_members/
        • show.js

In setting up the Rack app, I've used the following:

  def initialize
    super Rails.root.join('app')
    append_path('javascripts')

    if Rails.env.production?
      self.js_compressor = YUI::JavaScriptCompressor.new :munge => true, :optimize => true
      self.css_compressor = YUI::CssCompressor.new
    end
  end

When I attempt to //= require <views/staff_members/show> from application.js, I end up with Sprockets::FileNotFound: couldn't find file '<views/staff_members/show>'\n (in /Users/crimsonfox/RailsApps/gatescan/app/javascripts/application.js:1)

All subsequent attempts to load application.js result in Sprockets::CircularDependencyError: /Users/crimsonfox/RailsApps/gatescan/app/javascripts/application.js has already been required until I restart my Rails server process.

Rails caching is current turned off.

I've noticed that I can call resolve within initialize, passing it 'views/staff_members/show' and it will return the correct path to the file. I'm not sure why the file can't be found via require <views/staff_members/show>.

To summarize, on a fresh restart I get FileNotFound and refreshes result in CircularDependencyError until a restart. However, if I use the double-quote method of require, I get the expected result. I'm fine with using the work-around. I'd just like to know if there's a bug in the other method, or if I've missed something critical in my understanding of how it works.

@josh
Copy link
Contributor

josh commented Jul 24, 2011

It looks like you are trying to use the old sprockets 1 require syntax. Second, beta.11 has been revoked from rubygems, you shouldn't be using it. I'd suggest using rails/master and sprockets/master as it has the latest bug fixes for the circular dependency stuff.

@josh josh closed this as completed Jul 24, 2011
@beverlycodes
Copy link
Author

I'll pull sprockets/master and see if I have better luck. Stuck with Rails 3.0 right now though.

Thanks.

On Jul 24, 2011, at 1:13 PM, joshreply@reply.github.com wrote:

It looks like you are trying to use the old sprockets 1 require syntax. Second, beta.11 has been revoked from rubygems, you shouldn't be using it. I'd suggest using rails/master and sprockets/master as it has the latest bug fixes for the circular dependency stuff.

Reply to this email directly or view it on GitHub:
#133 (comment)

@brentkirby
Copy link

I'm getting this same issue in a standalone Rack app I'm working on. Not sure if its a bug or if I'm just missing something :)

I'm making something similar to Serve or StaticMatic, but using sprockets for assets. Any time sass or js compilation throws an error (whether its a sprockets error or a sass error directly) once fixed, Sprockets hangs on a CircularDependency error until I stop and restart the server. Here is a gist of the Rack::Builder setup, and the class I'm using to serve assets.

I subclassed Sprockets::Environment so I could just configure it when initialized.

Everything works perfectly outside of that. It seems like on error, Sprockets doesn't clear out its existing cache etc. and considers the file already included when it continues. I'm wondering if some kind of ensure that clears the cache is all it needs to fix it, probably on this end. I tried looking through the source but no luck so far.

As a random side note, that gist may help anyone trying to use this outside of Rails :) Its actually quite easy to do. I haven't tried pre-compiling yet, but seems pretty straightforward.

@brentkirby
Copy link

Doing a quick test... calling expire_index! before sending the error response back to the browser seems to fix it. I'm not sure if thats the best way to solve it though.

I overrode javascript_exception_response and css_exception_response to test, then used a fake variable in a sass stylesheet, and did a couple invalid //= require's in my js. Before overriding it would hang on the CircularDependency error after fixing them. When I expire the index prior to output the problem goes away:

def javascript_exception_response(exception)      
  expire_index!
  super(exception)
end

def css_exception_response(exception)      
  expire_index!
  super(exception)
end

I'm thinking this is probably a good solution, since the existing file index would certainly change next request, when the user fixes the error.

@suranyami
Copy link

I also got this error, and it's certainly confusing, since the actual problem is the original Sprockets::FileNotFound, and not a circular dependency.

Have tried brentkirby's suggestion, and that works for me too.

kappezoro pushed a commit to kappezoro/sprockets that referenced this issue Dec 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants