Ruby on Rails Rake assets:precompile error

后端 未结 7 1439
-上瘾入骨i
-上瘾入骨i 2020-12-06 00:22

I\'m new in Rails development and this is my first deployment to Heroku. When I execute my application (after the deployment) there is an error:

2011-09-18T2         


        
相关标签:
7条回答
  • 2020-12-06 00:55

    I ran into this issue as well and I resolved it by doing the following:

    Open up config/environments/production.rb and make sure the following option is set to true:

    # Don't fallback to assets pipeline if a precompiled asset is missed
    config.assets.compile = true
    

    Then run:

    rake assets:precompile --trace RAILS_ENV=production
    

    Hope this helps!

    ~Kevin

    0 讨论(0)
  • I would recommend to use the new Cedar stack. It precompiles assets for you on deploy and overall plays nicer with Rails 3.1, although you will need to configure your app a little bit to work: add some gems to your Gemfile and create a Procfile. But it is still an easier way to go.

    0 讨论(0)
  • 2020-12-06 00:59

    I got the problem too. But you can

    rake assets:precompile RAILS_ENV=production
    

    in local, and push to heroku with public/assets. It's resolved.

    0 讨论(0)
  • 2020-12-06 01:00

    I had the same error message. My issue was an incorrectly specified font url.

    The bulk of this answer shows how I figured it out.

    Although I didn't get the path of the asset it was failing on when running

    RAILS_ENV=production SECRET_KEY_BASE=xxx rake assets:precompile --trace
    

    Instead I had this stack trace:

    ** Invoke assets:precompile (first_time)
    ** Invoke assets:environment (first_time)
    ** Execute assets:environment
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute assets:precompile
    rake aborted!
    NoMethodError: undefined method `[]' for nil:NilClass
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_processor.rb:283:in `sprockets_context'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_processor.rb:124:in `asset_path'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_processor.rb:142:in `asset_url'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_processor.rb:214:in `font_url'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/script/tree/funcall.rb:143:in `_perform'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/script/tree/node.rb:58:in `perform'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/script/tree/list_literal.rb:63:in `block in _perform'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/script/tree/list_literal.rb:63:in `map'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/script/tree/list_literal.rb:63:in `_perform'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/script/tree/node.rb:58:in `perform'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:397:in `visit_prop'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/base.rb:36:in `visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:160:in `block in visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/stack.rb:79:in `block in with_base'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/stack.rb:115:in `with_frame'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/stack.rb:79:in `with_base'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:160:in `visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:433:in `block (2 levels) in visit_rule'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:433:in `map'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:433:in `block in visit_rule'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:181:in `with_environment'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:431:in `visit_rule'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/base.rb:36:in `visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:160:in `block in visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/stack.rb:79:in `block in with_base'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/stack.rb:115:in `with_frame'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/stack.rb:79:in `with_base'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:160:in `visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/base.rb:52:in `map'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/base.rb:52:in `visit_children'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:169:in `block in visit_children'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:181:in `with_environment'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:168:in `visit_children'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/base.rb:36:in `block in visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:188:in `visit_root'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/base.rb:36:in `visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:159:in `visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/visitors/perform.rb:8:in `visit'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/root_node.rb:36:in `css_tree'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/tree/root_node.rb:20:in `render'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sass-3.4.22/lib/sass/engine.rb:281:in `render'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_compressor.rb:48:in `call'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_compressor.rb:28:in `call'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:134:in `load_from_unloaded'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:60:in `block in load'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/loader.rb:44:in `load'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/cached_environment.rb:47:in `load'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/base.rb:66:in `find_asset'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/base.rb:73:in `find_all_linked_assets'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/manifest.rb:142:in `block in find'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:209:in `each'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:209:in `stat_directory'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/path_utils.rb:227:in `stat_tree'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:105:in `each'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:105:in `block in logical_paths'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:104:in `each'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/legacy.rb:104:in `logical_paths'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/manifest.rb:140:in `find'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/manifest.rb:185:in `compile'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-rails-3.1.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/rake/sprocketstask.rb:147:in `with_logger'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-rails-3.1.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
    /Users/smithd98/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:152:in `invoke_task'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
    /Users/smithd98/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
    

    I modified the gem to spit out the filename

    subl /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_processor.rb:124:in
    

    like this

      def asset_path(path, options = {})
        path = path.value
        puts path
        puts '123'
    
        path, _, query, fragment = URI.split(path)[5..8]
        puts '126'
        path     = sprockets_context.asset_path(path, options)
        puts '128'
        query    = "?#{query}" if query
        puts '130'
        fragment = "##{fragment}" if fragment
        puts '132'
        Autoload::Sass::Script::String.new("#{path}#{query}#{fragment}", :string)
      end
    

    Then when I ran

    RAILS_ENV=production SECRET_KEY_BASE=xxx rake assets:precompile --trace
    

    I got

    ** Invoke assets:precompile (first_time)
    ** Invoke assets:environment (first_time)
    ** Execute assets:environment
    ** Invoke environment (first_time)
    ** Execute environment
    ** Execute assets:precompile
    fonts/OpenSans-Light.ttf
    123
    126
    rake aborted!
    NoMethodError: undefined method `[]' for nil:NilClass
    /Users/smithd98/.rvm/gems/ruby-2.3.1/gems/sprockets-3.7.0/lib/sprockets/sass_processor.rb:283:in `sprockets_context'
    ...the rest of the stack trace is the same...
    

    Then I found out the issue was a font had been specified like this:

    .btn-rect {
      font-family: 'OpenSans-Light';
      src:font-url('fonts/OpenSans-Light.ttf') format('truetype');
    }
    

    and should have been like this:

    .btn-rect {
      font-family: 'OpenSans-Light';
    }
    
    0 讨论(0)
  • 2020-12-06 01:08

    Instead of config.assets.compile = true use config.serve_static_assets = true

    The first option is incorrect, because it tells your server to go back to serving the app/assets folder.

    0 讨论(0)
  • 2020-12-06 01:12

    Oh, this is an easy one. Your PG gem is breaking your rake task. You can either go the long route to try to fix it, or you can try commenting it out from your gemfile in order to run the precompile.

    0 讨论(0)
提交回复
热议问题