5

After creating or updating a Symfony 2.6.1 project with composer, I get a "Vendor libraries must be installed" error and it suggests running php composer.phar install to install them.

The exact steps I'm taking:-

composer create-project symfony/framework-standard-edition my_new_project/
cd my_new_project

This appears to run without any problems, and as far as I can tell, does download all the necessary vendor packages. However if I then run:-

php app/check.php

This results in:-

* Vendor libraries must be installed
  > Vendor libraries are missing. Install composer following
  > instructions from http://getcomposer.org/. Then run "php
  > composer.phar install" to install them.

I've tried running composer update, composer install, deleting the composer cache, but nothing I have tried so far resolves this error.

From testing numerous versions of Symfony, I get this error with all versions of Symfony >= 2.5.0. Any project I create in the same way using Symfony <= 2.4.8 works just fine.

I'm running PHP 5.6.4 (installed via MacPorts) on OS X.

I'm bit of a noob when it comes to composer, so any help would be much appreciated!

monkeyhybrid
  • 356
  • 3
  • 10

1 Answers1

5

This issue is here:

/**
 * In some special setups, the vendor/ directory isn't located in the project's
 * root directory. To make this command work for every case, read Composer's
 * vendor/ directory location directly from composer.json file.
 *
 * @return string
 */
private function getComposerVendorDir()
{
    $composerJson = json_decode(file_get_contents(__DIR__.'/../composer.json'));
    if (isset($composerJson->config)) {
        return $composerJson->config->{'vendor-dir'};
    }

    return __DIR__.'/../vendor/composer';
}

Specifically:

return $composerJson->config->{'vendor-dir'};

The condition on isset($composerJson->config) returns true, which leads to the above statement. However when you look at the generated composer.json:

"config": {
    "bin-dir": "bin"
},

The vendor-dir is missing. Generating the notice:

PHP Notice:  Undefined property: stdClass::$vendor-dir

Therefore the function returns null, so this requirement fails:

$this->addRequirement(
    is_dir($this->getComposerVendorDir()), // <-- HERE
    'Vendor libraries must be installed',
    'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
        'Then run "<strong>php composer.phar install</strong>" to install them.'
);

This is a bug on the symfony/symfony-standard. It's likely it is already in line to be fixed, but you may as well raise it on Github.

EDIT:

It looks like they already have, 2.7 uses:

$this->addRequirement(
    is_dir(__DIR__.'/../vendor/composer'),
    'Vendor libraries must be installed',
    'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
    'Then run "<strong>php composer.phar install</strong>" to install them.'
);

There is nothing wrong with your project, its just a bug in the standard edition. So long as you are autoloading classes properly you are fine.

Flosculus
  • 6,880
  • 3
  • 18
  • 42
  • Thank you for such an informative and detailed answer! I'm very happy to have it confirmed that my project is in fact ok. I was a little surprised to not see more reports of this issue on the web, but it is nice to know it looks to be resolved in the upcoming 2.7 release. Cheers! – monkeyhybrid Jan 02 '15 at 16:48
  • Np. Be aware that the standard edition is not technically part of Symfony2. Any requirements it suggests are easily broken when or if you start customizing the structure of your application. When you create the project, you don't get a copy of the GIT repo, so any changes you make to the project, or even to the requirements are yours alone. – Flosculus Jan 02 '15 at 17:01
  • 3
    I've added line `"vendor-dir": "vendor"` below `"bin-dir": "bin",` in `composer.json` and check passed. – Kosta Jan 04 '15 at 02:33
  • I couldn't get it to work with the above answer and comments but this one did the trick: http://stackoverflow.com/questions/27748135/symfony2-config-php-troubles-notice-undefined-property-stdclassvendor-dir – caramba Jan 06 '15 at 21:42