assetic icon indicating copy to clipboard operation
assetic copied to clipboard

Can not find module "less" on windows + assetic hangs

Open hellomedia opened this issue 12 years ago • 16 comments

Running symfony 2.0.9 on windows 7 with assetic 1.0.x branch ( latest commit b143e360eecf2346a1128eb0630b02ab83c3a3a8 ). Running into this error with Less filter ( this is the output of the css file ):

/*
[exception] 500 | Internal Server Error | RuntimeException
[message] 
[1] RuntimeException: 
                at n/a
                    in E:\wamp\www\hellokot\vendor\assetic\src\Assetic\Filter\LessFilter.php line 103

                at Assetic\Filter\LessFilter->filterLoad(object(Assetic\Asset\FileAsset))
                    in E:\wamp\www\hellokot\vendor\assetic\src\Assetic\Filter\FilterCollection.php line 62

                at Assetic\Filter\FilterCollection->filterLoad(object(Assetic\Asset\FileAsset))
                    in E:\wamp\www\hellokot\vendor\assetic\src\Assetic\Asset\BaseAsset.php line 83

                at Assetic\Asset\BaseAsset->doLoad('/*!

I have tried with these branches and get the same error.

lessc-bin ( c274e92b0f46e2d57eb520be5723384a4a0de40e ) inherit-env ( 56cae6720ae1a24650960f2cfc58a8d27f4203a0 )

Trying to catch a more interesting error in assetic/Util/process.php with

die(var_dump($this->status));

leads me to this comand

"C:\Program Files (x86)\nodejs\node.exe" "C:\Windows\Temp\assFFB0.tmp"

Executing this command in the console gets this error

Error: Cannot find module 'less'

My understanding is that node.js is not given the correct path to less. This is my config.yml

less:
        node: "C:\\Program Files (x86)\\nodejs\\node.exe"
        node_paths: [ "C:\\Program Files (x86)\\nodejs" , "C:\\Program Files (x86)\\nodejs\\node_modules" ]
        apply_to: "\.less$"

I am quite stuck, thank you in advance for any hint.

hellomedia avatar Feb 15 '12 18:02 hellomedia

Here are the paths as in assetic/Filter/lessFilter.php :

 $this->nodeBin : C:\Program Files (x86)\nodejs\node.exe
 $this->nodePaths[0] : C:\Program Files (x86)\nodejs
 $this->nodePaths[1] : C:\Program Files (x86)\nodejs\node_modules

hellomedia avatar Feb 15 '12 20:02 hellomedia

After some debugging and searching, it appears to be a mix of issues.

  1. Updating to the master branch ( this commit 8b9acf8eb32512e053a4f220b36d9a8646dd49e9 ) solves part of the issue thanks to this fix cc2e9adb744df0704a5357adc1cf9287c427420f .
  2. Changing the $env to null solves the path issue ( if NODE_PATH is configured in your system path_variables ) https://github.com/kriswallsmith/assetic/issues/99
  3. I am left with (at least) a hanging issue ( https://github.com/symfony/symfony/issues/1987 ) which apparently is solved in php 5.3.9. I'll upgrade tomorrow and see how things go from there.

hellomedia avatar Feb 16 '12 19:02 hellomedia

I'm also having the same issue.

After moving shit around for hours.. the node script that gets generated does actually return the results but PHP hangs fetching the output.

Upgrading to 5.3.9 hasn't helped either.

noetix avatar Feb 19 '12 12:02 noetix

noetix our solution was to move on to Linux. Files bigger than 4096 bytes makes the system going for an infinite loop.

We were looking hard for a solution on Windows but it was taking to long and no solutions ahead. The quickest way for us was to install a virtual machine running Linux with a shared directory for dev.

antoinegomez avatar Feb 19 '12 12:02 antoinegomez

Php 5.3.9 almost fixed it for me, but not quite. Previous to php 5.3.9, files bigger that 2048 bytes invoked in proc_open ( in Process.php ) hangs. As you mention, if you just use the node script that gets generated in command line, it works fine. For small css / js files, it works too. With php 5.3.9, the bug is solved up to 4096 bytes . Above that limit, it still hangs. After spending 2 days on this, my team conviced me to switch to linux. But maybe you can try this : https://bugs.php.net/bug.php?id=51800 ( change the STDERR descriptor to a file output ), and I suppose a php patch should be coming.

hellomedia avatar Feb 19 '12 14:02 hellomedia

For staging & production I use Debian and it took minutes to get it firing, but my local dev env is Windows 7. I guess a Linux VM would have worked, but it does seem like overkill.

Resolution, I've decided to use CSS version of Twitter Bootstrap. I'll revisit once PHP fixes the issue.

Thanks for your help guys.

noetix avatar Feb 26 '12 21:02 noetix

Any workaround for windows? I am using Windows 8 with PHP 5.4.7. Running php console assetic:dump, I get:

Dumping all dev assets. Debug mode is on. 18:51:01 [file+] C:/htdocs/site-ideiah-symfony/app/../web/css/57b3454.css [Assetic\Exception\FilterException] An error occurred while running: "C:\Users\Rafael\AppData\Local\Temp\ass1C74.tmp"

Error Output: Access Denied

dextervip avatar Jan 14 '13 20:01 dextervip

I have same problem, even I have already added a NODE_PATH for windows.

Also I tried to set both nodejs bin path and nodejs module path by:

new LessFilter('C:\Program Files\nodejs\node.exe', array('C:\Users\AlloVince\AppData\Roaming\npm\node_modules'));

there is not error messag but I got a empty output.

Then I tried to debug LessFilter.php by:

    $proc = $pb->getProcess();
    $code = $proc->run();
    //unlink($input);
    var_dump($code);
    var_dump($proc);
    var_dump($proc->getOutput());

The tmp file for nodejs created success as :

C:\Users\AlloVince\AppData\Local\Temp\ass1B1E.tmp

but the $proc->getOutput() is empty.

I direct run command send Symfony\Component\Process to is OK

cmd /V:ON /E:ON /C ""C:\Program Files\nodejs\node.exe" "C:\Users\AlloVince\AppData\Local\Temp\ass1B1E.tmp""

So my guess is the issue cause by Symfony\Component\Process not catch CMD output correct.

AlloVince avatar Jan 25 '13 10:01 AlloVince

I'm experiencing a similar problem a the users above, on a windows 7 x64 machine with php 5.4.7.

Using node v0.10.0, less was installed using npm install -g less

C:\nodejs>npm install -g less
npm http GET https://registry.npmjs.org/less
npm http 304 https://registry.npmjs.org/less
npm http GET https://registry.npmjs.org/ycssmin
npm http 304 https://registry.npmjs.org/ycssmin
C:\nodejs\lessc -> C:\nodejs\node_modules\less\bin\lessc
[email protected] C:\nodejs\node_modules\less
└── [email protected]

Running php app\console assetic:dump complains that the less module cannot be found,

Dumping all dev assets.
Debug mode is on.

12:14:43 [file+] web/css/bootstrap.css
  [Assetic\Exception\FilterException]
  An error occurred while running:
  "c:\nodejs\node.exe" "C:\Users\[username]\AppData\Local\Temp\ass20FC.tmp"

  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> (C:\Users\[username]\AppData\Local\Temp\ass20FC.tmp: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)

but running both
"c:\nodejs\node.exe" "C:\Users\[username]\AppData\Local\Temp\ass5A15.tmp" and "cmd /V:ON /E:ON /C ""c:\nodejs\node.exe" "C:\Users\[username]\AppData\Local\Temp\ass4A7B.tmp""" directly from command line produce the expected css output.

speelgoedkoper avatar Mar 13 '13 11:03 speelgoedkoper

Same problem here on Windows7 x64 on WAMP. from CMD the assetic:dump return:

An error occurred while running: "C:\Program Files (x86)\nodejs\node.exe" "C:\Users\Alessandro\AppData\Local \Temp\assE92D.tmp"

Input: /*!

  • Bootstrap v2.3.1 *
  • Copyright 2012 Twitter, Inc
  • Licensed under the Apache License v2.0 [...]

the problem is that also after some second C:\Users\Alessandro\AppData\Local\Temp\assE92D.tmp does not exist...

installed node and all the stuff just today from current repo.

aledelgo avatar May 06 '13 08:05 aledelgo

I was getting these problems. I realised that when you run:

npm install -g less

I noticed in the output that it installs the 'less' library into my user's roaming profile:

C:\Users\Ben\AppData\Roaming\npm\node_modules\less

When I put this path in my node_paths, the problem went away:

    less:
         node: "C:\\Program Files (x86)\\nodejs\\node.exe"
         node_paths: ["C:\\Users\\Ben\AppData\\Roaming\\npm\\node_modules"] 
         apply_to:   "\.less$"

onshop avatar Jun 21 '13 12:06 onshop

this is what I did, and it ran OK now. hope it is helpful to you less: node: C:\Program Files\nodejs\npm node_paths: ["C:\Program Files\nodejs\node_modules\npm\node_modules"] apply_to: ".less$"

dockuvn avatar Dec 02 '13 14:12 dockuvn

Just move your node_modules to C:\Users\USERNAME\ directory

FanFataL avatar Jul 09 '14 13:07 FanFataL

I've added such parameters to parameters.yml:

    assetic.node.paths:
        - D:/Development/Servers/nodejs/node_modules/npm/node_modules #this is where nodejs installed
        - C:/Users/Developer/AppData/Roaming/npm/node_modules #this is another (global?) path

Where first path is where nodejs installed, the Developer in the second path means current user name.

and it solved my problem.

smilesrg avatar Jul 30 '15 10:07 smilesrg

I tried all of these solution. Thanks @smilesrg !!! His modification solved my problem too !

Alexandre-T avatar Oct 13 '15 12:10 Alexandre-T

Found the same error in Win 7 x64 and PHP 5.6 Actually there was a series of missconfigurations.

  1. I installed Node for Windows X64 (msi installer) from here
  2. It will be installed in folder C:\Program Files\nodejs (default install options assumed)
  3. After install, I made sure that the executable is on my PATH (it will be configured by default, but double check by executing npm version from a new DOS windows).

Here is where things are getting interesting. The modules are meant to be found in C:\Program Files\nodejs\node_modules (as suggested from many people above, as well as my initial asumption).

However in my case it was in C:\Program Files\nodejs\node_modules\npm. I found that out because during the installation of the Less module, the installer was giving me warnings about file package.json not being found. And the only place where I found it was int that directory.

Not sure what the actual directory should be. Just find the package.json within the Node folder, and write that down.

  1. In a new DOS window, execute cd <the_package.json_dir>
  2. Once positioned in that directory, execute npm install less. It will take few seconds, and hopefully you won't get any warning.
  3. Double check that the folder <the_package.json_dir>\node_modules\less has been created.
  4. At this point there are two options: To follow the instructions provided by @smilesrg, or to add that directory to the assetic.yml file. In my case, it looks like (notice the double backslashes):
assetic:
   ...   
   filters:
      less:
         node: "node"
         node_paths:
            - "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\"
            ...
         apply_to: "\\.less$"
   ...

zuzsso avatar Dec 04 '16 20:12 zuzsso