简体   繁体   English

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

[英]Unable to load Sass / Compass after installing RVM, to use with Assetic in Symfony2

I was trying to use Capifony, which requires Capistrano, which requires Ruby. 我试图使用Capifony,它需要Capistrano,而后者需要Ruby。 But my apt version of ruby was old and was throwing syntax errors. 但是我的Ruby apt版本过旧,并引发语法错误。 So then I installed RVM and did this: 因此,我安装了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

Copied and pasted those paths to config.yml 将这些路径复制并粘贴到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$"

Everything about Compass and Sass worked fine before switching to RVM. 在切换到RVM之前,有关Compass和Sass的所有操作均正常。 Compass/Sass still seem to work from app_dev.php, but they break when I try to dump assets for production: 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;                                                                                                                                 
  } 

Another error I have been getting: 我得到的另一个错误:

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)

Related: @mpapis @jamz Sass broken after install with RVM, using Assetic PHP 相关:@mpapis @jamz 使用Assetic PHP与RVM安装后,Sass断开了

I would like to add more tags: compass and sass. 我想添加更多标签:指南针和sass。 Not sure if can be done with higher score. 不知道是否可以用更高的分数来完成。

UPDATE 更新

I added a wrapper like this: 我添加了一个这样的包装器:

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

And edited config.yml again, but now I get these errors alternated, randomly: 并再次编辑config.yml,但是现在我交替出现这些错误:

Error 1: 错误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;                                                                                                                                 
  } 

Error 2: 错误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' 

Compass still works fine through app_dev.php 指南针仍然可以通过app_dev.php正常工作

I guess you need a wrapper: 我想你需要一个包装纸:

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

this will generate wrappers which will call proper ruby(rvm) environment, use them like: 这将生成包装,该包装将调用适当的ruby(rvm)环境,如下所示使用它们:

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

Solution

Just use lessphp . 只需使用lessphp即可 It can be installed with Composer, and then in config.yml: 它可以与Composer一起安装,然后在config.yml中安装:

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

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

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