个性化阅读
专注于IT技术分析

如何解决Composer安装/更新错误:PackageVersions\Installer::activate()的返回值必须是PackageVersions\void的实例,不返回任何值

当你尝试使用composer或依赖composer的项目中的任何其他CLI任务更新/安装软件包时, 将看到以下异常:

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

基本上与一个错误有关, 该错误由你用来执行任何操作的PHP版本引起。在我们的案例中, 我们遇到了Ocramius的PackageVersions软件包的异常。幸运的是, 他很快解决了Github上报告的问题。

使用PHP> = 7.1

尽管没有关于该项目的官方自述文件的信息, 但是该库至少需要PHP 7.1才能正常工作:

{
    "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"
    }, ....
}

(显然, 在库编写器的安装过程中, 如果它在CLI上找到了PHP 7.0, 则不允许这样做, 但是许多开发人员在不同的计算机上使用相同的项目, 但在同一项目中使用不同的版本)。例如, 在本地环境中使用PHP 7.2时通常会发生这种情况, 但是不幸的是, 在服务器中, 你使用的是PHP CLI 7.0。

基本上, 你将需要使用其他版本的PHP运行命令。如果使用PHP> = 7.1版本运行命令后问题仍然存在, 请删除供应商文件夹, 然后使用PHP> = 7.1版本CLI重新安装依赖项。

编码愉快!

赞(0)
未经允许不得转载:srcmini » 如何解决Composer安装/更新错误:PackageVersions\Installer::activate()的返回值必须是PackageVersions\void的实例,不返回任何值

评论 抢沙发

评论前必须登录!