1

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)                               
hgf
  • 575
  • 3
  • 14
  • Is Coffeescript really working or is Less just the first one to fail? – Aurélien Thieriot Feb 14 '14 at 14:32
  • Less is the first one to fail. – hgf Feb 14 '14 at 14:37
  • If I disable the less filter, everything works fine, including coffescript. – hgf Feb 14 '14 at 14:46
  • I know it is not an answer, but would might be interested by this PHP implementation of a LESS compiler: http://isometriks.com/using-less-with-symfony2 – Aurélien Thieriot Feb 14 '14 at 14:56
  • I generally think that having your node dependencies in the sources is a bad idea (Better to handle npm install as part of your process), so I would tend to think that the error is somewhere between node_paths and running your Symfony command in sudo... But if the rest is working, I'm clueless – Aurélien Thieriot Feb 14 '14 at 14:58
  • I replaced it with lessphp and is ok now, but I fear to have compatibility issues in the future. Hope not. – hgf Feb 14 '14 at 17:33

1 Answers1

0

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$"
Guilherme Viebig
  • 6,901
  • 3
  • 28
  • 30