Rails 4 - 本地资产预编译错误

时间:2015-06-19 03:47:48

标签: ruby-on-rails-4 asset-pipeline

在开发(rails 4.2 app)中,我们使用以下命令进行本地资产预编译:

$ RAILS_ENV=production bundle exec rake assets:clean assets:precompile RAILS_RELATIVE_URL_ROOT=/tj --trace
** Invoke assets:clean (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:clean
** Invoke assets:precompile (first_time)
** Invoke assets:environment
** Execute assets:precompile
rake aborted!
Sass::SyntaxError: Invalid CSS after "...ontent}*/ url(C": expected comma, was ":/Program Files..."
(sass):66
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:1162:in `expected'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/lexer.rb:221:in `expected!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:463:in `block in arglist'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:460:in `loop'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:460:in `arglist'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:445:in `fn_arglist'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:407:in `funcall'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:387:in `ident'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:246:in `unary_not'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:246:in `unary_div'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:246:in `unary_minus'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:246:in `unary_plus'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:227:in `times_div_or_mod'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:227:in `plus_or_minus'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:227:in `relational'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:227:in `eq_or_neq'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:227:in `and_expr'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:227:in `or_expr'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:364:in `space'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:345:in `interpolation'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:293:in `expr'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:571:in `assert_expr'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/script/parser.rb:62:in `parse'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:1024:in `sass_script'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:877:in `value!'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:750:in `block in try_declaration'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:1138:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:1138:in `rethrow'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:763:in `try_declaration'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:693:in `declaration_or_ruleset'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:658:in `block_child'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:650:in `block_contents'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:639:in `block'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:632:in `ruleset'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:657:in `block_child'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:650:in `block_contents'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:117:in `stylesheet'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/scss/parser.rb:42:in `parse'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/engine.rb:393:in `_to_tree'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sass-3.4.14/lib/sass/engine.rb:268:in `render'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/sass_compressor.rb:48:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/sass_compressor.rb:28:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:86:in `load_asset_by_uri'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:45:in `block in load'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:155:in `fetch_asset_from_dependency_cache'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/loader.rb:38:in `load'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in `yield'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in `load'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/base.rb:63:in `find_asset'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/base.rb:70:in `find_all_linked_assets'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:138:in `block in find'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:223:in `block in stat_tree'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:207:in `block in stat_directory'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in `each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in `stat_directory'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:222:in `stat_tree'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:226:in `block in stat_tree'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:207:in `block in stat_directory'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in `each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in `stat_directory'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:222:in `stat_tree'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in `each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in `block in logical_paths'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in `each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in `logical_paths'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:136:in `find'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:162:in `compile'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-3.2.0/lib/rake/sprocketstask.rb:147:in `with_logger'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
c:/Ruby200/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
c:/Ruby200/lib/ruby/gems/2.0.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
c:/Ruby200/bin/rake:23:in `load'
c:/Ruby200/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile

错误是在sass中的parser.rb中引起的。我们不太明白错误的含义。我们尝试在生产服务器上部署,并且上述资产预编译命令成功运行,没有任何错误。有人可以帮我们理解错误和/或修复吗?

4 个答案:

答案 0 :(得分:3)

确保您的css文件语法正确且正确缩进。 或者你可以从gem文件中卸载你的sass gem ......但这不是一个好的解决方案.. 尝试纠正你的css语法..

答案 1 :(得分:1)

检查SASS文件的第66行。

Sass::SyntaxError: Invalid CSS after "...ontent}*/ url(C": expected comma, was      
":/Program Files..."(sass):66

看起来像一个无效的CSS错误。我猜你在试图链接到外部文件?你必须检查路径。

可能不能使用'C:/ Program Files ...',而是将其更改为与您的文件相关的relative path,即

url(../../external_directory/image.png)

答案 2 :(得分:1)

回滚版sprockets' from 3.2.0 to 2.12.3 , the error disappeared. The error seems to be caused by incompatible version of sprockets`版本后,它为Rails执行资产预编译。

答案 3 :(得分:0)

当遇到以下代码时,sass处理器(位于sass gem中)会抛出语法错误:

ontent}*/ url(C:/Program

在预编译一个本地gem资产时,资产管道生成哪些代码(很可能是jquery-ui-rails gem,文件jquery-ui-rails-xxx \ app \ assets \ javascripts \ jquery-ui \ theme .css.erb,以下一行):

background: #ffffff/*{bgColorContent}*/ url(<%= image_path("jquery-ui/ui-bg_flat_75_ffffff_40x100.png") %>)

如果您需要找到确切的错误位置,您可以暂时评论以下行:

was = was[0...15] + "..." if was.size > 18
在saas gem中,sass-x.x.x \ lib \ sass \ scss \ parser.rb文件, def self.expected(扫描仪,预期,线)方法。

由于config.relative_url_root中的值不正确,image_path助手方法没有使用资产的正确路径(relative_url_root似乎已被弃用,但仍由image_path使用)。 http://apidock.com/rails/ActionView/Helpers/AssetUrlHelper/asset_path

使用Rails.application.config.action_controller.relative_url_root(如ckeditor_rails)的其他gem在预编译时会产生相同的问题。

使用RAILS_RELATIVE_URL_ROOT参数运行预编译任务(或rails控制台)时出现问题。 运行

RAILS_RELATIVE_URL_ROOT /yourapprelativeurl rails c

你会看到错误的路径:

p Rails.application.config.action_controller.relative_url_root 

一种解决方法是在application.rb中设置:

config.action_controller.relative_url_root = "" #or "yourapprelativeurl"

这将预编译gems资产,但也可能有其他意外结果。