Shopify / sprockets-commoner

Use Babel in Sprockets to compile JavaScript modules for the browser
MIT License
182 stars 22 forks source link

Exclude Sprockets 4 manifest.js by default #48

Open amiuhle opened 7 years ago

amiuhle commented 7 years ago

Using Sprockets 4.0.0.beta4, I got the error below when trying to deploy. In development, everything worked fine, and adding exclude: ['vendor/bundle', 'app/assets/config'] in the initializer helped.

URI::InvalidURIError: expected file:// scheme:
/path/to/app/releases/20161024082816/app/assets/config/manifest.js:2
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-4.0.0.beta4/lib/sprockets/uri_utils.rb:95:in `parse_asset_uri'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-4.0.0.beta4/lib/sprockets/unloaded_asset.rb:136:in `load_file_params'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-4.0.0.beta4/lib/sprockets/unloaded_asset.rb:65:in `params'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-4.0.0.beta4/lib/sprockets/loader.rb:33:in `load'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-4.0.0.beta4/lib/sprockets/cached_environment.rb:21:in `block in initialize'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-4.0.0.beta4/lib/sprockets/cached_environment.rb:48:in `load'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-commoner-0.6.3/lib/sprockets/commoner/bundle.rb:71:in `block in call'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-commoner-0.6.3/lib/sprockets/commoner/bundle.rb:65:in `map'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-commoner-0.6.3/lib/sprockets/commoner/bundle.rb:65:in `call'
/path/to/app/shared/bundle/ruby/2.3.0/gems/sprockets-commoner-0.6.3/lib/sprockets/commoner/bundle.rb:54:in `call'

app/assets/config/manifest.js:

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
schneems commented 7 years ago

Ping, any ideas here, could there be a problem in this gem? Does shopify still use this gem? cc/ @bouk @TylerHorth

rafaelfranca commented 7 years ago

Weird. We do use this gem and we also use the manifest file even with sprockets 3 and we don't see this error in our application. Maybe something changed in sprockets or sprockets-rails that is including the manifest file in the bundle?

bouk commented 7 years ago

Yes, we still use this gem but I don't think we currently have an application that's being deployed with it and Sprockets 4

@amiuhle could you provide some more information on when this happens and what your application looks like? I assumed this would happen when precompiling the assets, but I can't reproduce it

schneems commented 7 years ago

The issue seems to be cache related. The problem only happens on the second push. I'm shooting in the dark here, but maybe shopify deploys with the same absolute path to the cache? Versus this app is running on Heroku and gets a different path on each deploy.

TylerHorth commented 7 years ago
# sprockets/uri_utils.rb
    def parse_asset_uri(uri)
      scheme, _, path, query = split_file_uri(uri)

      unless scheme == 'file'
        raise URI::InvalidURIError, "expected file:// scheme: #{uri}"
      end

      return path, parse_uri_query_params(query)
    end

Might be worth throwing a debugger in there and seeing what the uri is before the exception is raised. Might give us some hints towards what is actually going wrong here.

amiuhle commented 7 years ago

I just tried to reproduce this, but couldn't... I don't think it's worth putting any more effort into this, at least if someone else has the same problem, they'll find the workaround above.

If you agree, you can close this. Thanks for the feedback!

schneems commented 7 years ago

@TylerHorth uri is in the exception output alread. I think it's either false or nil or empty string:

raise URI::InvalidURIError, "expected file:// scheme: #{uri}"
# => "URI::InvalidURIError: expected file:// scheme: "
TylerHorth commented 7 years ago

Ah. You're right, I missed that. It's probably nil since that's what resolve returns when a file cant be found.

I don't have enough knowledge of commoner to make a guess as to what could have gone wrong, but if it can no longer be reproduced it's probably not worth more investigation.

dimroc commented 7 years ago

I just ran into this issue and I'm wondering if it's related to an issue I ran into here: https://github.com/rails/sprockets/issues/451

dimroc commented 7 years ago
remote:        URI::InvalidURIError: expected file:// scheme:
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/app/assets/config/manifest.js:1
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/uri_utils.rb:94:in `parse_asset_uri'
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/unloaded_asset.rb:134:in `load_file_params'
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/unloaded_asset.rb:64:in `params'
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:34:in `load'
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-commoner-0.6.4/lib/sprockets/commoner/bundle.rb:70:in `block in call'
remote:        /tmp/build_02fbcf7b380e429bf9912ee9e770601c/vendor/bundle/ruby/2.4.0/gems/sprockets-commoner-0.6.4/lib/sprockets/commoner/bundle.rb:64:in `map'

Full stack here: https://gist.github.com/dimroc/7cedcf211e966fb1065b18ce3313fc79

bouk commented 7 years ago

Ohhh I just realized we don't run into this because our manifest.js is not included in our commoner compilation. I can probably reproduce this now

dimroc commented 7 years ago

I've never run into this locally, only when deploying to Heroku. For anyone else that stumbles into this, you can get by with heroku repo:purge_cache. But that might be a temporary fix.

ian commented 7 years ago

Same problem over here. @dimroc's solution works everytime for me as a crutch. Is there a more permanent solution that anyone has found?

dimroc commented 7 years ago

For anyone else frustrated by this, I got around the problem by not using the new manifest.js and returning to the initializers/assets.rb way of doing things. sprockets-commoner works fine in that scenario.

Rails.application.config.assets.version = '1.1.5'
Rails.application.config.assets.precompile += [
  %w{client.js vendor.js},
  %w{admin.css dealership.css}
].flatten
xuanchien commented 5 years ago

Got this issue today and @dimroc's solution worked. But we need to install Heroku Repo plugin first

https://github.com/heroku/heroku-repo