【问题标题】:Uncaught TypeError: Return value of Magento\InventoryComposerInstaller must be an instance of Magento\InventoryComposerInstaller\void, none returned未捕获的类型错误:Magento\InventoryComposerInstaller 的返回值必须是 Magento\InventoryComposerInstaller\void 的实例,没有返回
【发布时间】:2019-07-18 22:37:23
【问题描述】:

我正在尝试通过 composer 在我的网络服务器上安装 Magento 2。在必须将以下内容添加到 composer.json 文件中以使所有内容在使用 php 版本的情况下在公平竞争环境中运行:

"config": {
    "platform": {
        "php": "7.2.14"
    }
} 

然后当我composer install

Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 392 installs, 0 updates, 0 removals
  - Installing magento/magento-composer-installer (0.1.13): Downloading (100%)
  - Installing symfony/polyfill-ctype (v1.10.0): Downloading (100%)
  - Installing symfony/polyfill-mbstring (v1.10.0): Downloading (100%)
  - Installing zendframework/zend-stdlib (2.7.7): Downloading (100%)
  - Installing zendframework/zend-hydrator (1.1.0): Downloading (100%)
  - Installing psr/container (1.0.0): Downloading (100%)
  - Installing container-interop/container-interop (1.2.0): Downloading (100%)
  - Installing zendframework/zend-validator (2.11.1): Downloading (100%)
  - Installing zendframework/zend-escaper (2.6.0): Downloading (100%)
  - Installing zendframework/zend-uri (2.6.1): Downloading (100%)
  - Installing psr/http-message (1.0.1): Downloading (100%)
  - Installing zendframework/zend-diactoros (1.8.6): Downloading (100%)
  - Installing zendframework/zend-loader (2.6.0): Downloading (100%)
  - Installing zendframework/zend-http (2.8.4): Downloading (100%)
  - Installing zendframework/zend-psr7bridge (0.2.2): Downloading (100%)
  - Installing zendframework/zend-servicemanager (2.7.11): Downloading (100%)
  - Installing zendframework/zend-filter (2.9.1): Downloading (100%)
  - Installing zendframework/zend-inputfilter (2.10.0): Downloading (100%)
  - Installing zendframework/zend-form (2.13.0): Downloading (100%)
  - Installing zendframework/zend-eventmanager (2.6.4): Downloading (100%)
  - Installing zendframework/zend-code (3.3.1): Downloading (100%)
  - Installing zendframework/zend-console (2.7.0): Downloading (100%)
  - Installing zendframework/zend-mvc (2.7.15): Downloading (100%)
  - Installing zendframework/zend-math (2.7.1): Downloading (100%)
  - Installing zendframework/zend-crypt (2.6.0): Downloading (100%)
  - Installing tedivm/jshrink (v1.3.1): Downloading (100%)
  - Installing symfony/process (v4.1.11): Downloading (100%)
  - Installing symfony/console (v4.1.11): Downloading (100%)
  - Installing oyejorge/less.php (v1.7.0.14): Downloading (100%)
  - Installing psr/log (1.1.0): Downloading (100%)
  - Installing monolog/monolog (1.24.0): Downloading (100%)
  - Installing magento/zendframework1 (1.14.1): Downloading (100%)
  - Installing symfony/finder (v4.2.3): Downloading (100%)
  - Installing symfony/filesystem (v4.2.3): Downloading (100%)
  - Installing seld/phar-utils (1.0.1): Downloading (100%)
  - Installing seld/jsonlint (1.7.1): Downloading (100%)
  - Installing justinrainbow/json-schema (5.2.8): Downloading (100%)
  - Installing composer/xdebug-handler (1.3.2): Downloading (100%)
  - Installing composer/spdx-licenses (1.5.0): Downloading (100%)
  - Installing composer/semver (1.4.2): Downloading (100%)
  - Installing composer/ca-bundle (1.1.4): Downloading (100%)
  - Installing composer/composer (1.8.4): Downloading (100%)
  - Installing colinmollenhour/credis (1.10.0): Downloading (100%)
  - Installing colinmollenhour/php-redis-session-abstract (v1.4.0): Downloading (100%)
  - Installing magento/framework (102.0.0): Downloading (100%)
  - Installing magento/inventory-composer-installer (1.0.3): Downloading (100%)  
PHP Fatal error:  Uncaught TypeError: Return value of Magento\InventoryComposerInstaller\Plugin::initModuleDeployment() must be an instance of Magento\InventoryComposerInstaller\void, none returned in /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php:69
Stack trace:
#0 /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php(88): Magento\InventoryComposerInstaller\Plugin->initModuleDeployment()
#1 /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php(82): Magento\InventoryComposerInstaller\Plugin->getModuleDeployment()
#2 [internal function]: Magento\InventoryComposerInstaller\Plugin->onPackageChange(Object(Composer\Installer\PackageEvent))
#3 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(176): call_user_func(Array, Object(Composer\Installer\PackageEvent))
#4 phar:///usr/lib/plesk-9.0/comp in /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php on line 69

Fatal error: Uncaught TypeError: Return value of Magento\InventoryComposerInstaller\Plugin::initModuleDeployment() must be an instance of Magento\InventoryComposerInstaller\void, none returned in /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php:69
Stack trace:
#0 /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php(88): Magento\InventoryComposerInstaller\Plugin->initModuleDeployment()
#1 /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php(82): Magento\InventoryComposerInstaller\Plugin->getModuleDeployment()
#2 [internal function]: Magento\InventoryComposerInstaller\Plugin->onPackageChange(Object(Composer\Installer\PackageEvent))
#3 phar:///usr/lib/plesk-9.0/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(176): call_user_func(Array, Object(Composer\Installer\PackageEvent))
#4 phar:///usr/lib/plesk-9.0/comp in /var/www/vhosts/blah/project-community-edition/vendor/magento/inventory-composer-installer/src/Plugin.php on line 69

我没有运气四处寻找与 Magento 相关的这个问题的帮助。一些与 Composer 相关的类似问题,但与 Magento 无关,用户要求提供有关 composer 版本和 php 版本等的更多信息。以下是这些线程中请求的信息:

$ composer --version
Composer version 1.9-dev (blah) 2019-02-08 16:02:33

$ composer show composer/composer | grep versions
versions : * 1.8.4

$ composer depends composer/composer
magento/framework  102.0.0  requires  composer/composer (^1.6)

$ php -version
PHP 7.0.32-0ubuntu0.16.04.1 (cli) ( NTS )

Plesk 中的 PHP 版本:7.2.14

phpinfo() 中列出的 PHP 版本:7.2.14

目前,我对如何处理这个问题感到困惑。任何建议或指示将不胜感激。这是我第一次使用 Composer 进行安装,由于缺乏对 linux/bash 等的理解/经验,我通常会尽量避免使用命令行。

提前致谢

【问题讨论】:

  • 您也应该将 CLI 版本更改为 PHP 7.2。该软件包似乎使用 PHP 7.1 作为最低版本(因为他们在其代码中使用返回类型 void,直到 PHP 7.1 才引入)。
  • 感谢@MagnusEriksson,我将与主持人交谈。我们之前讨论过 CLI 版本,但是主持人表示在 composer.conf 文件中添加指定 php 版本应该可以修复 php 版本不兼容问题。担心的是已经在使用 CLI 的其他网站(即我想要移动到此 M2 安装的 M1 实例)可能产生的影响。
  • 问题在于 composer 是一个 PHP 包,它使用 PHP 运行。因此,它需要使用 PHP 读取 composer 文件,然后才能知道它应该使用哪个 PHP 版本。我不确定您的主机是如何处理的,但这听起来有点奇怪。
  • 平台配置可用于告诉 Composer 在解析依赖项时采用哪个 PHP 版本。但是,这仅应用于强制使用较旧的 PHP 版本,以用于使用比稍后执行应用程序的版本更新的 PHP 版本执行 Composer 的情况。因此,在您的情况下,您可以将其设置为较旧的 PHP 版本(即 7.0.32)。

标签: php magento composer-php magento2


【解决方案1】:

此错误可能与 PHP 兼容性有关:

  • 对于Magento 2.3.1+PHP 7.1PHP 7.2

  • 对于Magento 2.3.0PHP 7.1

  • 对于Magento 2.2PHP 7.1PHP 7.0

  • 对于Magento 2.1PHP 7.1PHP 7.0PHP 5.6

  • 对于Magento 2.0PHP 7.0PHP 5.6PHP 5.5

检查您的 PHP 版本,并根据需要升级或降级 PHP。

如果没有好的 PHP 版本,您将永远无法让 Magento 2 正常工作

【讨论】:

  • 感谢您和那些对我的问题发表评论的人的回复。似乎我被误导了在 composer.conf 文件中指定 webserver php 版本的影响。我将我的网络服务器 php 降级到与我的服务器 CLI php 版本(7.0.32)匹配的版本,并安装了 Magento 2.2.7,没有任何进一步的错误或问题。稍后我将考虑升级 CLI php 版本,然后我将能够将 Magento 升级到最新版本。
  • 这个答案现在是错误的,即使是:阅读兼容性问题。 Magento 2.3.1 于 2019 年 3 月发布,兼容 PHP 7.2。
  • @PolRavalitera,感谢您的评论。你是对的,我只是编辑我的答案。
猜你喜欢
  • 2018-08-21
  • 2017-04-22
  • 2018-10-18
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 2015-06-29
相关资源
最近更新 更多