InstalledVersions.php: No such file or directory

How to fix a problem with composer in Docker that results in: failed to open stream: No such file or directory error for InstalledVersions.php.

2504 views
d

By. Jacob

Edited: 2022-04-08 07:45

I just fixed a very interesting problem with composer in a Docker container, the precise error I got was complaining about InstalledVersions.php not being found, with a typical No such file or directory error message. The specific error was:

object(ErrorException)#85 (8) { ["message":protected]=> string(122) "Warning: include(/sw6/vendor/composer/../composer/InstalledVersions.php): failed to open stream: No such file or directory" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(46) "/sw6/vendor/symfony/debug/DebugClassLoader.php" ["line":protected]=> int(163) ["trace":"Exception":private]=> array(6) { [0]=> array(1) { ["function"]=> string(17) "spl_autoload_call" } [1]=> array(3) { ["file"]=> string(81) "/sw6/vendor/composer/package-versions-deprecated/src/PackageVersions/Versions.php" ["line"]=> int(10) ["function"]=> string(12) "class_exists" } [2]=> array(3) { ["file"]=> string(40) "/sw6/vendor/shopware/core/HttpKernel.php" ["line"]=> int(178) ["function"]=> string(17) "spl_autoload_call" } [3]=> array(5) { ["file"]=> string(40) "/sw6/vendor/shopware/core/HttpKernel.php" ["line"]=> int(135) ["function"]=> string(12) "createKernel" ["class"]=> string(24) "Shopware\Core\HttpKernel" ["type"]=> string(2) "->" } [4]=> array(5) { ["file"]=> string(40) "/sw6/vendor/shopware/core/HttpKernel.php" ["line"]=> int(80) ["function"]=> string(8) "doHandle" ["class"]=> string(24) "Shopware\Core\HttpKernel" ["type"]=> string(2) "->" } [5]=> array(5) { ["file"]=> string(21) "/sw6/public/index.php" ["line"]=> int(103) ["function"]=> string(6) "handle" ["class"]=> string(24) "Shopware\Core\HttpKernel" ["type"]=> string(2) "->" } } ["previous":"Exception":private]=> NULL ["severity":protected]=> int(2) }

There are probably multiple reasons why this happens, but in my case I found that I was using the wrong version of composer. The production server was running composer 1.10.1 while my Docker container was using composer 2.0+ – the solution I found was to install the older version instead.

To install an older version of Composer, you will need to add it to your Dockerfile, like this:

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.10.1

Note. The --version=1.10.1 parameter allows you to request a specific version of Composer. I expect you can run the same command on a server or local computer, after uninstalling your existing version of docker – and of course you run it without the "RUN" part, since that is specifically for the Dockerfile :-)

If you do use Docker, remember to do the following after editing your Dockerfile:

1. Make sure your Docker container is not running: docker-compose down

2. Rebuild your docker container: docker-compose build

3. Now you can run your fixed container: docker-compose up - remember, you can use -d parameter here if you want to run your container detached.

After doing this you may need to log into your container and run:

composer dump-autoload

This should fix potential issues with the autoloader that may have resulted from using the wrong version of composer with a project that depends on a specific version. Good luck!

Tell us what you think:

  1. Here is the reason why the Shopware build script may not progress beyond: Dumped plugin configuration.
  2. How to fix a problem that happens when another container is occupying the specified port in Docker.

More in: Docker