Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hellomedia opened this issue Feb 15, 2012 · 16 comments
Open

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

hellomedia opened this issue Feb 15, 2012 · 16 comments

Comments

@hellomedia
Copy link

Running symfony 2.0.9 on windows 7 with assetic 1.0.x branch ( latest commit b143e36 ).
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 ( c274e92 )
inherit-env ( 56cae67 )

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
Copy link
Author

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
Copy link
Author

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

  1. Updating to the master branch ( this commit 8b9acf8 ) solves part of the issue thanks to this fix cc2e9ad .
  2. Changing the $env to null solves the path issue ( if NODE_PATH is configured in your system path_variables )
    Assetic and yui_css generating empty files #99
  3. I am left with (at least) a hanging issue ( Process.php problems symfony/symfony#1987 ) which apparently is solved in php 5.3.9. I'll upgrade tomorrow and see how things go from there.

@noetix
Copy link

noetix commented Feb 19, 2012

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.

@antoinegomez
Copy link

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.

@hellomedia
Copy link
Author

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.

@noetix
Copy link

noetix commented Feb 26, 2012

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.

@dextervip
Copy link

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

@AlloVince
Copy link

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.

@speelgoedkoper
Copy link

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.

@aledelgo
Copy link

aledelgo commented May 6, 2013

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.

@onshop
Copy link

onshop commented Jun 21, 2013

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$"

garak pushed a commit to garak/symfony-docs that referenced this issue Nov 2, 2013
I was testing, testing and testing one and another method or posibility, until I reached that page: kriswallsmith/assetic#185 that opened my eyes, and one value was missing:

node_paths /usr/lib/node_modules

I continously received:
[exception] 500 | Internal Server Error | Assetic\Exception\FilterException
[message] An error occurred while running:
&symfony#39;/usr/bin/node&symfony#39; &symfony#39;/tmp/assetic_styluswWvcnS&symfony#39;
Error Output:
module.js:340
throw err;
^
Error: Cannot find module &symfony#39;stylus&symfony#39;

so, this fixes and finishes my 6 hours quest.
@dockuvn
Copy link

dockuvn commented Dec 2, 2013

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$"

@FanFataL
Copy link

FanFataL commented Jul 9, 2014

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

@smilesrg
Copy link

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.

@Alexandre-T
Copy link

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

@zuzsso
Copy link

zuzsso commented Dec 4, 2016

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$"
   ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests