How to solve Composer Install/Update error: Return value of PackageVersions\Installer::activate() must be an instance of PackageVersions\void, none returned

How to solve Composer Install/Update error: Return value of PackageVersions\Installer::activate() must be an instance of PackageVersions\void, none returned

The exception that you will see when you try to update/install packages with composer or any other CLI task inside a project that relies on composer will be the following one:

PHP Fatal error:  Uncaught TypeError: Return value of PackageVersions\Installer::activate() must be an instance of PackageVersions\void, none returned in /var/www/vhosts/ourcodeworld.com/httpdocs/ourcodeworld/vendor/ocramius/package-versions/src/PackageVersions/Installer.php:80
Stack trace:
#0 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(236): PackageVersions\Installer->activate(Object(Composer\Composer), Object(Composer\IO\ConsoleIO))
#1 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(205): Composer\Plugin\PluginManager->addPlugin(Object(PackageVersions\Installer))
#2 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(261): Composer\Plugin\PluginManager->registerPackage(Object(Composer\Package\CompletePackage))
#3 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(76): Composer\Plugin\PluginManager->loadRepository(Object(Composer\Repository\InstalledFilesystemRepository))
#4 phar:///usr/lib/plesk-9.0/composer.p in /var/www/vhosts/ourcodeworld.com/httpdocs/ourcodeworld/vendor/ocramius/package-versions/src/PackageVersions/Installer.php on line 80

Fatal error: Uncaught TypeError: Return value of PackageVersions\Installer::activate() must be an instance of PackageVersions\void, none returned in /var/www/vhosts/ourcodeworld.com/httpdocs/ourcodeworld/vendor/ocramius/package-versions/src/PackageVersions/Installer.php:80
Stack trace:
#0 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(236): PackageVersions\Installer->activate(Object(Composer\Composer), Object(Composer\IO\ConsoleIO))
#1 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(205): Composer\Plugin\PluginManager->addPlugin(Object(PackageVersions\Installer))
#2 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(261): Composer\Plugin\PluginManager->registerPackage(Object(Composer\Package\CompletePackage))
#3 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/Plugin/PluginManager.php(76): Composer\Plugin\PluginManager->loadRepository(Object(Composer\Repository\InstalledFilesystemRepository))
#4 phar:///usr/lib/plesk-9.0/composer.p in /var/www/vhosts/ourcodeworld.com/httpdocs/ourcodeworld/vendor/ocramius/package-versions/src/PackageVersions/Installer.php on line 80

And is related basically to a error that is cause by the version of PHP that you are using to do whatever you're doing. In our case, we faced the exception with the PackageVersions package by Ocramius. Fortunately, he solved quickly the reported issue on Github.

Use PHP >= 7.1

Although there's no information on the official readme of the project, the library requires at least PHP 7.1 in order to work properly:

{
    "name": "ocramius/package-versions",
    "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)",
    "type": "composer-plugin",
    "license": "MIT",
    "authors": [
        {
            "name": "Marco Pivetta",
            "email": "ocramius@gmail.com"
        }
    ],
    "require": {
        "php":                 "^7.1.0",
        "composer-plugin-api": "^1.0.0"
    },

....
}

(obviously during the installation of the library composer wouldn't allow this if it founds PHP 7.0 on the CLI, however many developers work with different versions in different machines but with the same project). Usually happens when you work for example with PHP 7.2 in your local environment, but unfortunately in your server, you used the PHP CLI 7.0.

You will need basically to run the commands with a different version of PHP. If after running the command with the PHP >= 7.1 version, the problem persists, delete the vendor folder and install dependencies again using the  PHP >= 7.1 version CLI.

Happy coding !

This could interest you

Become a more social person