Symfony 2.3 does not work well with "less" embedded in project

786 Views Asked by At

I'm embedding all my node.js dependencies inside the project and all work, except "less". Any idea on how to fix that?

Here is my config:

assetic:
debug:          %kernel.debug%
use_controller: false
node: "%assetic_node%"
node_paths:
    - "%kernel.root_dir%/Resources/node_modules/"
    - "%kernel.root_dir%/Resources/node_modules/less/node_modules/"
    - "/usr/lib/node_modules/"
    - "/usr/local/lib/node_modules/"
    - "/opt/local/lib/node_modules/"
    - "/root/node_modules/"
filters:
    cssmin: ~
    cssrewrite: ~
    less:
        apply_to: "\.less$"
        bin: %kernel.root_dir%/Resources/node_modules/less/bin/lessc
    coffee:
        apply_to: "\.coffee$"
        bin: %kernel.root_dir%/Resources/node_modules/coffee-script/bin/coffee
    uglifyjs2:
        apply_to: "\.js$"
        bin: %kernel.root_dir%/Resources/node_modules/uglify-js/bin/uglifyjs
    uglifycss:
        apply_to: "\.css$"
        bin: %kernel.root_dir%/Resources/node_modules/uglifycss/uglifycss

I get the following error when running assetic:dump:

  [Assetic\Exception\FilterException]                                             
  An error occurred while running:                                                
  '/usr/bin/node' '/tmp/assetic_lessFnBKuF'                                       

  Error Output:                                                                   

  module.js:340                                                                   
      throw err;                                                                  
            ^                                                                     
  Error: Cannot find module 'less'                                                
      at Function.Module._resolveFilename (module.js:338:15)                      
      at Function.Module._load (module.js:280:25)                                 
      at Module.require (module.js:364:17)                                        
      at require (module.js:380:17)                                               
      at Object.<anonymous> (/tmp/assetic_lessFnBKuF:1:74)                        
      at Module._compile (module.js:456:26)                                       
      at Object.Module._extensions..js (module.js:474:10)                         
      at Module.load (module.js:356:32)                                           
      at Function.Module._load (module.js:312:12)                                 
      at Function.Module.runMain (module.js:497:10)                               
1

There are 1 best solutions below

0
Guilherme Viebig On

First make sure you have less and its dependencies installed in your system:

npm install less -g

Next, depending on your distro, node_modules can reside in different locations, so check if you have less installed, and where is lessc. Check my config:

less:
    bin: /usr/bin/lessc
    node: /usr/bin/nodejs
    node_paths: [/usr/lib/node_modules]
    apply_to: "\.less$"