Error creating new Laravel project with ‘composer create-project’

After upgrading (or installing) version 1.0.0-beta1 of Composer, I found that I was unable to successfully create a new Laravel project using composer create-project command. It appeared that everything was successful, but the dependency resolution process fails with this error message (or similar) when running the command composer create-project laravel/laravel laravel "5.1.*" --prefer-dist:

 [RuntimeException]                                                                                                                                                                      
Error Output: PHP Warning:  require(/home/vagrant/laravel/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/laravel/bootstrap/autoload.php on line 17                                                                                                                                                    
PHP Fatal error:  require(): Failed opening required '/home/vagrant/laravel/bootstrap/../vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/vagrant/larave/bootstrap/autoload.php on line 17

Upon investigation, you’ll find that this line is trying to load autoload.php from the Laravel (Composer) vendor directory, but that the vendor directory does not yet exist. There is some discussion and debate on GitHub Composer project issue #5066 about whether this is a Composer problem or Laravel problem. However, it does not seem clear about whether or not there will be a fix for the issue.

In the meantime, you can work around the problem by reverting to version 1.0.0-alpha11 (or earlier) version of Composer to return the previous behavior. To do so, follow the usual instructions on the Composer site for command-line installation, except when running php composer-setup.php (or sudo php composer-setup.php on Linux), use the --version option to specify version 1.0.0-alpha11 (or earlier). For example:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer --version=1.0.0-alpha11

Subsequently, you should be able to run composer create-project to create your new project.

After you have created your project, you can upgrade to the later version of Composer, using composer self-update, but, of course, you’ll have to revert to version 1.0.0-alpha11 (or earlier) the next time you create another project. Nevertheless, for doing updates to existing projects, such as adding packages, the later version works fine.

Advertisements