kriswallsmith / assetic

Asset Management for PHP
MIT License
3.75k stars 555 forks source link

Cannot find module 'less' #702

Open hackzilla opened 9 years ago

hackzilla commented 9 years ago

I have a strange error:

app/console assetic:dump --env=prod -vvv
Dumping all prod assets.
Debug mode is on.

10:13:45 [file+] /var/www/app.com/htdocs/app/../web/assetic/bootstrap_less.less
        /var/www/app.com/htdocs/vendor/hackzilla/bootstrap-bundle/Hackzilla/Bundle/BootstrapBundle/Resources/less/compile.less

  [Assetic\Exception\FilterException]                                                      
  An error occurred while running:                                                         
  '/usr/local/bin/node' '/tmp/assetic_lessAu0LRg'                                          
  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_lessAu0LRg: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)                                        
  Input:                                                                                   
  @import "variables.less";                                                                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/mixins.less";                
  // Reset and dependencies                                                                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/normalize.less";             
  @import "../../../../../../../../vendor/twbs/bootstrap/less/print.less";                 
  @import "../../../../../../../../vendor/twbs/bootstrap/less/glyphicons.less";            
  // Core CSS                                                                              
  @import "../../../../../../../../vendor/twbs/bootstrap/less/scaffolding.less";           
  @import "../../../../../../../../vendor/twbs/bootstrap/less/type.less";                  
  @import "../../../../../../../../vendor/twbs/bootstrap/less/code.less";                  
  @import "../../../../../../../../vendor/twbs/bootstrap/less/grid.less";                  
  @import "../../../../../../../../vendor/twbs/bootstrap/less/tables.less";                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/forms.less";                 
  @import "../../../../../../../../vendor/twbs/bootstrap/less/buttons.less";               
  // Components                                                                            
  @import "../../../../../../../../vendor/twbs/bootstrap/less/component-animations.less";  
  @import "../../../../../../../../vendor/twbs/bootstrap/less/dropdowns.less";             
  @import "../../../../../../../../vendor/twbs/bootstrap/less/button-groups.less";         
  @import "../../../../../../../../vendor/twbs/bootstrap/less/input-groups.less";          
  @import "../../../../../../../../vendor/twbs/bootstrap/less/navs.less";                  
  @import "../../../../../../../../vendor/twbs/bootstrap/less/navbar.less";                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/breadcrumbs.less";           
  @import "../../../../../../../../vendor/twbs/bootstrap/less/pagination.less";            
  @import "../../../../../../../../vendor/twbs/bootstrap/less/pager.less";                 
  @import "../../../../../../../../vendor/twbs/bootstrap/less/labels.less";                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/badges.less";                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/jumbotron.less";             
  @import "../../../../../../../../vendor/twbs/bootstrap/less/thumbnails.less";            
  @import "../../../../../../../../vendor/twbs/bootstrap/less/alerts.less";                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/progress-bars.less";         
  @import "../../../../../../../../vendor/twbs/bootstrap/less/media.less";                 
  @import "../../../../../../../../vendor/twbs/bootstrap/less/list-group.less";            
  @import "../../../../../../../../vendor/twbs/bootstrap/less/panels.less";                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/responsive-embed.less";      
  @import "../../../../../../../../vendor/twbs/bootstrap/less/wells.less";                 
  @import "../../../../../../../../vendor/twbs/bootstrap/less/close.less";                 
  // Components w/ JavaScript                                                              
  @import "../../../../../../../../vendor/twbs/bootstrap/less/modals.less";                
  @import "../../../../../../../../vendor/twbs/bootstrap/less/tooltip.less";               
  @import "../../../../../../../../vendor/twbs/bootstrap/less/popovers.less";              
  @import "../../../../../../../../vendor/twbs/bootstrap/less/carousel.less";              
  // Utility classes                                                                       
  @import "../../../../../../../../vendor/twbs/bootstrap/less/utilities.less";             
  @import "../../../../../../../../vendor/twbs/bootstrap/less/responsive-utilities.less";  

Exception trace:
 () at /var/www/app.com/htdocs/vendor/kriswallsmith/assetic/src/Assetic/Exception/FilterException.php:40
 Assetic\Exception\FilterException::fromProcess() at /var/www/app.com/htdocs/vendor/kriswallsmith/assetic/src/Assetic/Filter/LessFilter.php:152
 Assetic\Filter\LessFilter->filterLoad() at /var/www/app.com/htdocs/vendor/kriswallsmith/assetic/src/Assetic/Filter/FilterCollection.php:62
 Assetic\Filter\FilterCollection->filterLoad() at /var/www/app.com/htdocs/vendor/kriswallsmith/assetic/src/Assetic/Asset/BaseAsset.php:94
 Assetic\Asset\BaseAsset->doLoad() at /var/www/app.com/htdocs/vendor/kriswallsmith/assetic/src/Assetic/Asset/FileAsset.php:65
 Assetic\Asset\FileAsset->load() at /var/www/app.com/htdocs/vendor/kriswallsmith/assetic/src/Assetic/Asset/BaseAsset.php:103
 Assetic\Asset\BaseAsset->dump() at /var/www/app.com/htdocs/vendor/kriswallsmith/assetic/src/Assetic/Asset/AssetCollection.php:151
 Assetic\Asset\AssetCollection->dump() at /var/www/app.com/htdocs/vendor/symfony/assetic-bundle/Command/AbstractCommand.php:119
 Symfony\Bundle\AsseticBundle\Command\AbstractCommand->doDump() at /var/www/app.com/htdocs/vendor/symfony/assetic-bundle/Command/AbstractCommand.php:51
 Symfony\Bundle\AsseticBundle\Command\AbstractCommand->dumpAsset() at /var/www/app.com/htdocs/vendor/symfony/assetic-bundle/Command/DumpCommand.php:117
 Symfony\Bundle\AsseticBundle\Command\DumpCommand->execute() at /var/www/app.com/htdocs/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:253
 Symfony\Component\Console\Command\Command->run() at /var/www/app.com/htdocs/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:882
 Symfony\Component\Console\Application->doRunCommand() at /var/www/app.com/htdocs/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at /var/www/app.com/htdocs/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/app.com/htdocs/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at /var/www/app.com/htdocs/app/console:22

assetic:dump [--forks="..."] [--watch] [--force] [--period="..."] [write_to]

However when I run the command manually it works.

'/usr/local/bin/node' '/tmp/assetic_lessAu0LRg'

This all worked when I was using Symfony 2.3, but not when using Symfony 2.6, when running on Ubuntu.

user@tso1:~/htdocs$ node --version
v0.10.26
user@tso1:~/htdocs$ less --version
less 458 (GNU regular expressions)

config.yml

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:
        - FOSUserBundle
        - HackzillaBootstrapBundle
    java: /usr/bin/java
    filters:
      cssembed:
        jar: %kernel.root_dir%/Resources/java/cssembed-0.4.5.jar
      cssrewrite: ~
      yui_js:
        jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
      less:
          node: /usr/local/bin/node
          node_paths: [/usr/local/lib/node_modules]
          apply_to: "\.less$"
    assets:
      bootstrap_less:
          inputs:
              - '@HackzillaBootstrapBundle/Resources/less/compile.less'
          filters: [less,cssembed]
      bootstrap_modal_less:
          inputs:
              - '@HackzillaBootstrapBundle/Resources/less/compile.less'
              - '@MyBundle/Resources/public/css/modal.css'
              - '@MyBundle/Resources/public/css/modal_close.css'
          filters: [less,cssembed]

I have managed to find a fix to allow assetic to compile the less again, however I don't understand why it is nessessary:

ln -s /usr/lib/node_modules/ ~/.node_libraries
hackzilla commented 9 years ago

This issue maybe related to #688

hackzilla commented 9 years ago

Current version of assetic:

            "name": "kriswallsmith/assetic",
            "version": "v1.2.1",
            "source": {
                "type": "git",
                "url": "https://github.com/kriswallsmith/assetic.git",
                "reference": "b20efe38845d20458702f97f3ff625d80805897b"
            },

Previous version:

            "name": "kriswallsmith/assetic",
            "version": "v1.1.2",
            "source": {
                "type": "git",
                "url": "https://github.com/kriswallsmith/assetic.git",
                "reference": "735cffd3982c6e8cdebe292d5db39d077f65890f"
            },
raymon2683 commented 8 years ago

Did you install the less filter to be accessible globally? If not try the following: $ sudo npm install -g less And set the given path in your assetic filter setting.

gsw945 commented 7 years ago

I tried these ways(all not working for me):

  1. ln -s /usr/lib/node_modules/ ~/.node_libraries
  2. sudo npm install -g less
  3. modify js code string in function filterLoad of file vendor/kriswallsmith/assetic/src/Assetic/Filter/LessFilter.php, and the code require('less') throw exception with Cannot find module 'less' when i visit my php page everytime,, but I cant do it OK at system terminal with node shell.

ps: system info:

I solved this problem with using LessphpFilter instand of LessFilter, and that refer to stackoverflow

refer code as below:

<?php
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Filter\LessphpFilter;

// if you got error `Class 'lessc' not found`, 2 ways to solve:
// 1. execute `composer require leafo/lessphp`
// 2. download lessphp, and inclued code `require "path/to/lessc.inc.php";` in this file;

$css = new AssetCollection(array(
    new FileAsset(
        '/path/to/src/styles.less',
        array(new LessphpFilter())
    ),
));
echo $css->dump();
stof commented 7 years ago

you should configure the path to node libraries for your filter.

When using the bundle, it can be configured once for all filters using node.