简体   繁体   English

Ruby on Rails Rake资产:预编译错误

[英]Ruby on Rails Rake assets:precompile error

I'm new in Rails development and this is my first deployment to Heroku. 我是Rails开发的新手,这是我第一次部署到Heroku。 When I execute my application (after the deployment) there is an error: 当我执行我的应用程序(部署后)时出现错误:

2011-09-18T21:05:54+00:00 app[web.1]: Completed 500 Internal Server Error in 10ms
2011-09-18T21:05:54+00:00 app[web.1]:
2011-09-18T21:05:54+00:00 app[web.1]: ActionView::Template::Error (application.css isn't precompiled):

I googled this and found that I have to precompile my assets, but when trying to do this I found an other error: 我搜索了这个,发现我必须预编译我的资产,但是当我尝试这样做时,我发现了另一个错误:

$ bundle exec rake assets:precompile RAILS_ENV=production
rake aborted!
No such process - /usr/lib/ruby/gems/1.8/gems/pg-0.11.0/lib/pg_ext.so

(See full trace by running task with --trace)

I haven't found any solution for this issue. 我还没有找到解决这个问题的方法。 Is there anyone who faced this an know how to solve this problem? 是否有人知道如何解决这个问题?

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 : 打开config/environments/production.rb并确保将以下选项设置为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 凯文〜

I got the problem too. 我也遇到了问题。 But you can 但是你可以

rake assets:precompile RAILS_ENV=production

in local, and push to heroku with public/assets. 在本地,并通过公共/资产推送到heroku。 It's resolved. 它已经解决了。

I would recommend to use the new Cedar stack . 我建议使用新的Cedar堆栈 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. 它在部署时为您预编译资产,并且使用Rails 3.1整体播放效果更好,尽管您需要配置您的应用程序一些工作:向您的Gemfile添加一些宝石并创建一个Procfile。 But it is still an easier way to go. 但它仍然是一种更容易的方式。

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 我修改了gem以吐出文件名

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';
}

Oh, this is an easy one. 哦,这很简单。 Your PG gem is breaking your rake task. 你的PG宝石正在打破你的佣金任务。 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. 您可以选择漫长的路径来尝试修复它,也可以尝试从gemfile中注释掉它以运行预编译。

Yes like Simpleton posted above the PG gem is causing the problem. 是的就像Simpleton上面贴出的PG宝石造成的问题。 Imo a better solution would be to move the PG gem inside production in your gemfile and run; Imo更好的解决方案是将PG gem放在gemfile中生成并运行; bundle install --without production Then you should be able to run the rake task without problems bundle install --without production然后你应该能够毫无问题地运行rake任务

Instead of config.assets.compile = true use config.serve_static_assets = true 而不是config.assets.compile = true使用config.serve_static_assets = true

The first option is incorrect, because it tells your server to go back to serving the app/assets folder. 第一个选项不正确,因为它告诉您的服务器返回提供app / assets文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM