Rails 3.1.1 资产预编译 - rake 中止
Posted
技术标签:
【中文标题】Rails 3.1.1 资产预编译 - rake 中止【英文标题】:Rails 3.1.1 assets precompile - rake aborted 【发布时间】:2011-10-11 11:36:02 【问题描述】:编辑:还有其他人有什么建议吗?我完全被难住了!!!
我有一个应用程序,其中所有资产都可以正常编译,但在第二个应用程序中,当我运行时:
RAILS_ENV=production rake assets:precompile --trace
我收到以下消息:未定义方法“目录?”对于 nil:NilClass
请帮忙。当我查看 public/assets 目录时,我看到图像文件已被预编译,但没有任何 js 或 css 文件。
下面是完整的终端输出:
=> RAILS_ENV=production rake assets:precompile --trace
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/swamiatma/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
undefined method `directory?' for nil:NilClass
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/sprockets-2.0.2/lib/sprockets/base.rb:122:in `block in each_entry'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/sprockets-2.0.2/lib/sprockets/base.rb:118:in `each'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/sprockets-2.0.2/lib/sprockets/base.rb:118:in `each_entry'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/sprockets-2.0.2/lib/sprockets/base.rb:137:in `block in each_file'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/sprockets-2.0.2/lib/sprockets/base.rb:136:in `each'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/sprockets-2.0.2/lib/sprockets/base.rb:136:in `each_file'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/sprockets-2.0.2/lib/sprockets/base.rb:149:in `each_logical_path'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/actionpack-3.1.1/lib/sprockets/static_compiler.rb:18:in `compile'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/actionpack-3.1.1/lib/sprockets/assets.rake:52:in `internal_precompile'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/actionpack-3.1.1/lib/sprockets/assets.rake:66:in `block (3 levels) in <top (required)>'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/swamiatma/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/actionpack-3.1.1/lib/sprockets/assets.rake:56:in `block (3 levels) in <top (required)>'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/swamiatma/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/bin/rake:19:in `load'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile:primary
rake aborted!
Command failed with status (1): [/Users/swamiatma/.rvm/rubies/ruby-1.9.2-p2...]
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `call'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `sh'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `sh'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils.rb:78:in `ruby'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `ruby'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/actionpack-3.1.1/lib/sprockets/assets.rake:9:in `ruby_rake_task'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/actionpack-3.1.1/lib/sprockets/assets.rake:17:in `invoke_or_reboot_rake_task'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/gems/actionpack-3.1.1/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/swamiatma/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/bin/rake:19:in `load'
/Users/swamiatma/.rvm/gems/ruby-1.9.2-p290@lasource/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile
【问题讨论】:
我猜你在配置中做错了什么。错误输入路径或类似的东西。我会做一个捆绑打开链轮并添加一些调试输出以查看导致错误的路径。 你能给我举个例子如何在 sprockets 中进行这个调试吗? 您执行bundle open sprockets
,然后使用您最喜欢的文本编辑器添加 puts 语句、调试行或 pry 或任何适合您需要的工具。
你一定是个很好的人。我愿意,但我不知道该把这些陈述放在哪里。 sprockets 中有太多的文件和太多的代码,以至于我无法弄清楚将 puts 语句放在哪里以及要准确输出什么。可以多牵我一点手吗?
没关系,我意识到跟踪指向 base.rb 第 122 行。duh
【参考方案1】:
感谢 phoet:我刚刚在 .bundle/ruby/1.9.1/gems/sprockets-2.0.2/lib/sprockets/base.rb
处用 begin..rescue
块包围了这些行。该错误是由无效的符号链接引起的(仅在具有 rails 3.1.1 sprockets 2.0.2 的生产环境中,另外机架 1.3.4 导致了 constant WFKV_
警告但机架 1.3.3 没有)
120 paths << path
121 begin
122 if stat(path).directory?
123 each_entry(path) do |subpath|
124 paths << subpath
125 end
126 end
127 rescue
128 puts "error with directory #path"
129 end
现在错误消失了,bundle exec rake assets:precompile --trace
结束了,但在 tmp:cache:clear 之后的最后两个步骤 ** Execute assets:precompile:primary
需要一个永恒...我们会看到 ;)
【讨论】:
这里的关键词是“断开的符号链接”。【参考方案2】:感谢 Phoet 的建议,我在 sprockets 的基本文件中添加了 puts 语句,这给了我罪魁祸首文件。这是一个ckeditor js文件。我已将 ckeditor 移到公共目录中的管道之外,但是以某种方式要求包含此文件。我仍然不知道为什么。但是我在 assets/javascripts 目录中放了一个虚拟的 ckeditor.js 文件,这足以解决我的问题。
【讨论】:
以上是关于Rails 3.1.1 资产预编译 - rake 中止的主要内容,如果未能解决你的问题,请参考以下文章
Capistrano在部署时失败:资产:使用SSHKit预编译:: Command :: Failed:rake退出状态:1
rails and metronic - 资产预编译:SassC 错误,空间不足
ExecJS :: ProgramError:运行rake资产时意外的标记点«(»,预期的点«:»:在生产中进行预编译
rake assets:precompile RAILS_ENV=production 不能按要求工作