安装 RVM 后无法加载 Sass / Compass,与 Symfony2 中的 Assetic 一起使用

Posted

技术标签:

【中文标题】安装 RVM 后无法加载 Sass / Compass,与 Symfony2 中的 Assetic 一起使用【英文标题】:Unable to load Sass / Compass after installing RVM, to use with Assetic in Symfony2 【发布时间】:2012-07-29 22:18:52 【问题描述】:

我尝试使用 Capifony,它需要 Capistrano,它需要 Ruby。但是我的 ruby​​ apt 版本很旧,并且会抛出语法错误。然后我安装了 RVM 并这样做了:

$ rvm use 1.9.3
$ rvm --rvmrc --create use 1.9.3@myapp
$ gem install sass [--pre]
$ gem install compass [--pre]
$ updatedb
$ locate sass | grep myapp | grep bin
$ locate compass | grep myapp | grep bin

将这些路径复制并粘贴到 config.yml

    sass:
        bin: /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/sass-3.2.0.alpha.277/bin/sass
        #apply_to: "\.scss$"
    compass:
        bin: /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/bin/compass
        apply_to: "\.scss$"

在切换到 RVM 之前,关于 Compass 和 Sass 的一切都运行良好。 Compass/Sass 似乎仍然可以从 app_dev.php 工作,但是当我尝试转储资产进行生产时它们会中断:

$ rm -r app/cache/ # this is how I delete cache, any other way give me errors, even before having this compass problem. This have always worked fine. I removed the * because this code block was interpreting it as a comment
$ php app/console assetic:dump --env=prod --no-debug
Dumping all prod assets.
Debug mode is off.

00:05:36 [file+] /home/www/dev/public/myapp/app/../web/css/fcd6640.css



  [Assetic\Exception\FilterException]                                                                                                                  
  An error occurred while running:                                                                                                                     
  '/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby' '/usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/bin/compass' 'compile' '/t  
  mp' '--config' '/tmp/assetic_compassF1Mv7t' '--sass-dir' '' '--css-dir' '' '/tmp/assetic_compassKDoaEA.scss'                                         

  Error Output:                                                                                                                                        
  /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- sass (LoadError  
  )                                                                                                                                                    
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'                                      
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/lib/compass/dependencies.rb:6:in `rescue in <top (required)>'           
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/lib/compass/dependencies.rb:1:in `<top (required)>'                     
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'                                      
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'                                      
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/lib/compass.rb:5:in `block in <top (required)>'                         
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/lib/compass.rb:4:in `each'                                              
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/lib/compass.rb:4:in `<top (required)>'                                  
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'                                      
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'                                      
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/bin/compass:20:in `block in <main>'                                     
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/bin/compass:8:in `fallback_load_path'                                   
    from /usr/local/rvm/gems/ruby-1.9.3-p194@myapp/gems/compass-0.13.alpha.0/bin/compass:19:in `<main>'                                              


  Output:                                                                                                                                              
  Unable to load Sass. Please install it with one of the following commands:                                                                           
    gem install sass --pre                                                                                                                             


  Input:                                                                                                                                               
  $main-color: red;                                                                                                                                    

  body                                                                                                                                                
    color: $main-color;                                                                                                                                 
   

我遇到的另一个错误:

Error Output:                                                                                                                                        
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find compass (>= 0) amongst [big decimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError)

相关:@mpapis @jamz Sass broken after install with RVM, using Assetic PHP

我想添加更多标签:compass 和 sass。不知道能不能高分。

更新

我添加了一个这样的包装器:

$ rvm wrapper ruby-1.9.3-p194@myapp php sass compass

并再次编辑了 config.yml,但现在我会随机交替出现这些错误:

错误 1:

[Assetic\Exception\FilterException]                                                                                                                  
  An error occurred while running: '/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby' '/usr/local/rvm/bin/php_compass' 'compile' '/tmp' '--config' '/tmp/assetic_compass0Tmn8t' '--sass- dir' '' '--css-dir' '' '/tmp/assetic_compasssw2S3k.scss'                                                                                             

  Error Output: /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby: no Ruby script found in input (LoadError)                                              
Input:                                                                                                                                               
  $main-color: red;                                                                                                                                    

  body                                                                                                                                                    
    color: $main-color;                                                                                                                                 
   

错误 2:

Error Output: /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/shared_helpers.rb:22:in `default_gemfile': Could not locate Gemfile (Bundler::GemfileNotFound)                                                                                                                                
from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler.rb:213:in `default_gemfile' 

指南针通过 app_dev.php 仍然可以正常工作

【问题讨论】:

【参考方案1】:

解决方案

只需使用lessphp。可以用 Composer 安装,然后在 config.yml 中:

    lessphp:
         php: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php
         apply_to: "\.less"

【讨论】:

@alex88 我试过了,真的。我过去使用过 ruby​​ 和 rails。 ruby 废话就够了,php + less 就赢了。 哦,当然 :) 我也是,有时它可能是一个 PITA.. 缺少的一个很好的东西是精灵生成 :)【参考方案2】:

我猜你需要一个包装器:

rvm wrapper ruby-1.9.3-p194@myapp php sass compass

这将生成调用适当的 ruby​​(rvm) 环境的包装器,像这样使用它们:

sass:
    bin: /usr/local/rvm/bin/php_sass
    #apply_to: "\.scss$"
compass:
    bin: /usr/local/rvm/bin/php_compass
    apply_to: "\.scss$"

【讨论】:

谢谢,我试过了,但它抛出了另一个错误,我更新了我的帖子 这完全是随机的,现在它显示“无法找到 Gemfile (Bundler::GemfileNotFound)”。看起来像一个指南针错误,因为我没有使用 Bundler。 第二个错误尝试gem uninstall rubygems-bundler - compass 中有一个错误,当与rubygems-bundler 连接时可能会生成此错误

以上是关于安装 RVM 后无法加载 Sass / Compass,与 Symfony2 中的 Assetic 一起使用的主要内容,如果未能解决你的问题,请参考以下文章

即使在使用 rvm pkg install zlib 后也无法加载此类文件 - zlib

mac下用ruby安装sass && webstorm下给scss文件添加watch

无法在 ubuntu 12.04 上安装 rvm

安装ruby与compass sass环境

Vue CLI 和 SASS 加载器的大问题

metronic 4.5.7开发环境下, 在Windows 10上安装了10.16.0版本的node js之后,导致node sass无法加载