10

I have tested the YUI compressor in the command line (on windows) and it seems to work just fine.

But the .css created by assetic is not compressed, and comes with this message on the top (inside the .css!):

/*
[exception] 500 | Internal Server Error | RuntimeException
[message] 
[1] RuntimeException: 
            at n/a
                in E:\websites\symfony2\public_html\Symfony\vendor\assetic\src\Assetic\Filter\Yui\BaseCompressorFilter.php line 81

            at Assetic\Filter\Yui\BaseCompressorFilter->compress('

Is this a configuration problem? Or a bug in assetic?

Here's the code I used inside my twig template:

{% stylesheets '@CompanyBundlenameBundle/Resources/public/css/style.css' filter='yui_css' %}
<link rel="stylesheet" type="text/css" media="screen" href="{{ asset_url }}" />
{% endstylesheets %}
HappyDeveloper
  • 12,480
  • 22
  • 82
  • 117

7 Answers7

5

I have the same problem... (the problem seems present only on windows) The only way I found, is really dirty :

1 - Specify the java executable path in config file (at the same place of the yui jar declaration path)

yui_css:
    jar: "%kernel.root_dir%\\Resources\\java\\yuicompressor.jar"
    java: "C:\\Program Files\\Java\\jre6\\bin\\java.exe"

2 - Open the Assetic\Util\Process.php file Change the "proc_open" line (line 123 my version) in "run" method Original line :

$process = proc_open($this->commandline, $descriptors, $pipes, $this->cwd, $this->env, $this->options);

Modified line :

$process = proc_open('"'.$this->commandline.'"', $descriptors, $pipes, $this->cwd, $this->env, $this->options);

And it's works... but is not a real solution...

If someone has more info... thanks :)

Pierre
  • 51
  • 1
  • 1
5

If you're using the latest stable version (1.0.2), then it has a bug that prevents it from correctly using YUI compressor on Windows. As @Pierre has pointed out, the problem lies in the way the proc_open function is called, but the fix should be applied elsewhere.

If you have a look at Assetic\Util\ProcessBuilder class you'll find the culprit on line 95:

#95 if (defined('PHP_WINDOWS_MAJOR_VERSION')) {

There's no such constant in PHP as PHP_WINDOWS_MAJOR_VERSION ( http://php.net/manual/en/info.constants.php ), which makes the if statement test evaluate to false. What should be used instead is PHP_WINDOWS_VERSION_MAJOR.

The second issue I found in this class is a couple of lines below:

#102 if ($args) {
#103   $script .= ' '.implode(' ', array_map('escapeshellarg', $parts));
#104 }

$parts is not defined in this scope and should be replaced with $args.

As I found out later, both issues have been fixed on 16.09 in this commit: https://github.com/kriswallsmith/assetic/commit/cc2e9adb744df0704a5357adc1cf9287c427420f but the code hasn't been tagged yet.

Hope this helps.

Jan Molak
  • 4,426
  • 2
  • 36
  • 32
4

YUI compressor needs to be define in your app/config/config.yml like that :

assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        cssrewrite: ~
        yui_css:
            jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.6.jar

Of course, you need to download the YUI compressor and copy it in your /app/Resources/java/ directory.

Warning, the assetic bundle doesn't publish your compress CSS automaticly, you need to publish them manually with the following command:

php app/console assetic:dump 
egeloen
  • 5,844
  • 1
  • 27
  • 38
  • On dev it publishes them automatically. Anyway, I tried the dump command and the same error appeared: RuntimeException. This is frustrating, it seems like they only test the code on linux. – HappyDeveloper Jul 02 '11 at 17:45
  • I work on linux and I can't reproduce your bug on my system. Test the [symfony github](http://github.com/symfony/symfony) issue, the team are very reactive. – egeloen Jul 04 '11 at 18:53
3

I just got this same problem.

What i did to solve:

  • Open the "deps" file.
  • Remove the line "version=v1.0.0RC1" in "[AsseticBundle]" section.
  • Run "bin/vendors update" command to get the latest version of AsseticBundle.

Hope this helps.

fernanDOTdo
  • 111
  • 1
  • 4
3

Not sure if you resolved this, but I had the same issue today.

I followed the suggestions above, but still no joy.

So I looked into the 500 internal error and the error I was getting was:

[message] Warning: file_put_contents(): Filename cannot be empty in /Applications/MAMP/htdocs/shop/vendor/assetic/src/Assetic/Filter/Yui/BaseCompressorFilter.php line 84

I looked into the file at line 84 and that line had:

$input = tempnam(sys_get_temp_dir(), 'assetic_yui_compressor');

After some digging around and debugging I found that the permissions on my temp directory used by the sys_get_temp_dir() was wrong.

Once I resolved these permissions it worked fine.

I'm not sure if this was the same error you received, but if so hopefully this well help.

Cheers

Adam

Adam Stacey
  • 2,833
  • 4
  • 26
  • 38
2

Thanks to Jan Molak's post above, I was able to successfully run Assetic Less Filter in Symfony 2 on Windows Vista.

In my deps file I have changed

[assetic]
    git=http://github.com/kriswallsmith/assetic.git
    version=v1.0.3

into

[assetic]
    git=http://github.com/kriswallsmith/assetic.git
    version=cc2e9adb744df0704a5357adc1cf9287c427420f

and then run

php bin\vendors update

I hope that this update won't cause other problems. For now everything seems to work as expected.

qdb
  • 41
  • 2
0

After spending somme hours on this bug, I solved it while disabling yui_css on dev with :

Replace :

filter='yui_css'

by :

filter='?yui_css'

http://symfony.com/doc/current/cookbook/assetic/yuicompressor.html (Disable Minification in Debug Mode)

Romuald
  • 545
  • 1
  • 7
  • 16