alchaplinsky / polymer-rails

Polymer and web components for Ruby on Rails
MIT License
286 stars 80 forks source link

Error on rake assets:precompile when deploying to Heroku (undefined method 'paths' for nil) #76

Closed hankish closed 8 years ago

hankish commented 8 years ago

I'm having trouble replicating this on my development machine but when I'm deploying to heroku I get a NoMethodError: undefined method 'paths' for nil:NilClass error when it hits /lib/polymer-rails/processors/component.rb:50:in 'absolute_asset_path'. This is keeping me from deploying to production and I can't figure it out.

Here's the relevant part of component.rb (line 50 is ::Rails.application.assets.paths.each do |path|):

        def absolute_asset_path(file)
          search_file = file.sub(/^(\.\.\/)+/, '/').sub(/^\/*/, '')
          ::Rails.application.assets.paths.each do |path|
            file_list = Dir.glob( "#{File.absolute_path search_file, path }*")
            return file_list.first unless file_list.blank?
          end
          components = Dir.glob("#{File.absolute_path file, File.dirname(@context.pathname)}*")
          return components.blank? ? nil : components.first
        end

It makes sense that I'm getting it since sprockets 3 supposedly returns nil when config.assets.compile = false (as it is in production), but I'm confused as to why I'm not getting this issue when I run bundle exec rake assets:precompile on my local development machine.

Any ideas as to a solution?

My Gemfile

source 'https://rubygems.org'
ruby '2.1.2'

#=== CORE GEMS ===#

  gem 'rails', '4.2.5'
  gem 'puma', '~> 2.15'

#=== STORAGE, MODELS & QUEUEING ===#

  gem 'mongoid', '~> 5.0'
  gem 'redis', '~> 3.2.2'
  gem 'sidekiq', '~> 4.0'
  gem 'sinatra', :require => nil
  gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
  gem 'carrierwave_direct'
  gem 'fog'
  gem 'mini_magick', '~> 4.3.6'
  gem 'devise', '~> 3.5'
  gem 'devise-async'

#=== FRONT-END ===#

  gem 'sass-rails',   '~> 5.0'
  gem 'coffee-rails', '~> 4.1'
  gem 'uglifier', '~> 2.7'
  gem 'jquery-rails', '~> 4.1'
  gem 'bootstrap-sass', '2.3.2.2'
  gem 'simple_form', '~> 3.2'
  gem 'kaminari', '~> 0.16.3'
  gem 'kaminari-bootstrap', '~> 0.1.3'
  gem 'polymer-rails', '~> 1.2.4'
  gem 'polymer-elements-rails', '~> 1.0.1'

Partial Build Log

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
...
       I, [2016-02-13T22:45:28.972927 #832]  INFO -- : Writing /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/public/assets/website-eb0a5f2f888f38def002375115b50f6756c6cce81e85884166b0cc748dfe22f3.css
       I, [2016-02-13T22:45:28.973166 #832]  INFO -- : Writing /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/public/assets/website-eb0a5f2f888f38def002375115b50f6756c6cce81e85884166b0cc748dfe22f3.css.gz
       rake aborted!
       NoMethodError: undefined method `paths' for nil:NilClass
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/polymer-rails-1.2.4/lib/polymer-rails/processors/component.rb:50:in `absolute_asset_path'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/polymer-rails-1.2.4/lib/polymer-rails/processors/component.rb:20:in `block in require_imports'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `each'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/polymer-rails-1.2.4/lib/polymer-rails/processors/component.rb:19:in `require_imports'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/polymer-rails-1.2.4/lib/polymer-rails/processors/component.rb:12:in `process'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/polymer-rails-1.2.4/lib/polymer-rails/processors/sprockets_processor.rb:15:in `call'
       /tmp/build_8d57aa386ad1ac964185a5cf2f034c23/hankish-badgelist-20baeba02073432e2d20cbce0dbed639db778233/vendor/bundle/ruby/2.1.0/gems/polymer-rails-1.2.4/lib/polymer-rails/processors/sprockets_processor.rb:10:in `call'
hankish commented 8 years ago

Update: I can replicate the issue in development now (I had forgotten to set the environment to production). So to replicate the issue you just run: RAILS_ENV=production bundle exec rake assets:precompile

alchaplinsky commented 8 years ago

Hm.. looks like this is a common issue for a number of gems https://github.com/rails/sprockets-rails/issues/237. Since config.assets.compile is disabled for production environment there's no Rails.application.assets to prevent assets from compiling. However I've added a workaround by using Sprockets::CachedEnvironment which is now in v 1.2.4.1 cc @hankish

hankish commented 8 years ago

@alchapone: Thanks for the quick update! That definitely resolved my issue. Is it ok if I close this github issue then?

Just to drop this in here, the other big problem keeping this from working reliably in production is alchapone/polymer-elements-rails#11 over in the polymer-elements-rails gem. Could you throw some love over there when you have a minute? (I'm having to reference the github repo in my production gemfile which feels yucky.)