15

When I run:

php composer.phar require kartik-v/yii2-widgets "*"

I get the following output (using the -vvv verbose flag):

  - Installing kartik-v/bootstrap-fileinput (v4.1.7)
Downloading https://api.github.com/repos/kartik-v/bootstrap-fileinput/zipball/f95a7e5fa0a9db1ead445e438653aa71e9f599f9
    Downloading: connection...
    Downloading: 0%
    Downloading: 5%
    ...
    Downloading: 95%
    Downloading: 100%
    Downloading: 100%
Writing C:/Users/Michael/AppData/Local/Composer/files/kartik-v/bootstrap-fileinput/f95a7e5fa0a9db1ead445e438653aa71e9f599f9.zip into cache
    Extracting archive

  [ErrorException]
  ZipArchive::extractTo(): Full extraction path exceed MAXPATHLEN (260)

Exception trace:
 () at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Downloader/ZipDownloader.php:79
 Composer\Util\ErrorHandler::handle() at n/a:n/a
 ZipArchive->extractTo() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Downloader/ZipDownloader.php:79
 Composer\Downloader\ZipDownloader->extract() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Downloader/ArchiveDownloader.php:44
 Composer\Downloader\ArchiveDownloader->download() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Downloader/DownloadManager.php:201
 Composer\Downloader\DownloadManager->download() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer/LibraryInstaller.php:156
 Composer\Installer\LibraryInstaller->installCode() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer/LibraryInstaller.php:87
 Composer\Installer\LibraryInstaller->install() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer/InstallationManager.php:152
 Composer\Installer\InstallationManager->install() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer/InstallationManager.php:139
 Composer\Installer\InstallationManager->execute() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer.php:578
 Composer\Installer->doInstall() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Installer.php:225
 Composer\Installer->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Command/RequireCommand.php:154
 Composer\Command\RequireCommand->execute() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:253
 Symfony\Component\Console\Command\Command->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:195
 Symfony\Component\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:147
 Composer\Console\Application->doRun() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Symfony/Component/Console/Application.php:126
 Symfony\Component\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Console/Application.php:84
 Composer\Console\Application->run() at phar://C:/ProgramData/ComposerSetup/bin/composer.phar/bin/composer:43
 require() at C:\ProgramData\ComposerSetup\bin\composer.phar:25


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [packages1] ... [packagesN]

I even tried using the flag "--prefer-source" but I get the same error. Is there a way to tell composer to increase the MAXPATHLEN? Which path exactly is it complaining about?

Michael Lawson
  • 161
  • 1
  • 1
  • 4

5 Answers5

24

try using the --prefer-source flag

composer install --prefer-source
aaafly
  • 2,858
  • 1
  • 14
  • 11
  • This actualy did the trick for me. --prefer-source checkes out directly the repositorys. It takes a bit more time but does not run into the path issues. – Andreas May 31 '15 at 11:50
  • 1
    +1 it worked also for me on Windows, **NOTE:** but `composer update --prefer-source` did not. Only after removing vendor folder and running `install` i achieved case of cloning repos – Armen Jun 06 '16 at 17:07
  • This worked perfectly for me on a Windows 10 64-bit machine. Thanks! – Matt Cromwell Oct 13 '17 at 07:12
15

Composer is complaining about a path that is too long for PHP on Windows in the download. Windows has a max path length (MAXPATHLEN) of 260 characters so I don't think you can change that.

When I had this problem when installing Symfony, I fixed it by using a short path for the project directory (such as C:\projects\myproject).

While investigating this problem, I found it can also be fixed by using the --prefer-source flag when installing, like this:

php composer.phar install --prefer-source

Note that you need git in your Windows shell path for this to work, as this checks out the source from Github rather than downloading the distribution file. It is also slower.

Note also that you might have to remove the vendor/ folder before installing again using the --prefer-source flag:

rm -rf vendor/
tfrommen
  • 177
  • 3
  • 17
Richard F
  • 249
  • 3
  • 4
2

try to shorten your project full path like c://www/yii-project because windows operating system didn't allow directory more than 250 chars

Robert
  • 5,278
  • 43
  • 65
  • 115
Omar Ali
  • 21
  • 1
0

I believe it is complaining that this C:/Users/Michael/AppData/Local/Composer/files/kartik-v/bootstrap-fileinput/f95a7e5fa0a9db1ead445e438653aa71e9f599f9.zip is probably more then 256 chars. From what I know, you cannot have a path longer than that in Windows.

Not sure there is a solution to this. You can probably create a shorted path and have your application installed there.

Tine
  • 115
  • 9
Mihai P.
  • 9,307
  • 3
  • 38
  • 49
  • Thanks for the suggestion. I found on [link]https://getcomposer.org/doc/04-schema.md#config[/link] where you can add "config": { "cache-dir": "PATH" } to your composer.json file. I ran the install again, and although it used the new path I still received the same error at the same place and that file path is less than 90 characters. Looking at the error again I think it is less the cache directory and more the path it is unzipping the file to. I'd have to look at reconfiguring WAMP's root website directory to shorten it somehow. – Michael Lawson Mar 19 '15 at 14:24
0

Try run in command line

mklink /j <Link> <Target> 

to create symbolic link and decrease your filepath length to less than 260 chars. More details https://technet.microsoft.com/en-us/library/cc753194(v=ws.11).aspx

Nikeos
  • 1
  • 1