Bootstrap

laravel官方升级引起的报错问题解决

laravel的illuminate/http模块和illuminate/support由于升级导致不兼容

laravel框架启动失败,报错信息如下:

$ php artisan 

Fatal error: Trait "Illuminate\Support\Traits\InteractsWithData" not found in /Users/linxi/app/live-class-service/vendor/illuminate/http/Concerns/InteractsWithInput.php on line 12

Fatal error: Uncaught ReflectionException: Class "Illuminate\Http\Request" does not exist in /Users/linxi/app/live-class-service/vendor/illuminate/container/Container.php:944
Stack trace:
#0 /Users/linxi/app/live-class-service/vendor/illuminate/container/Container.php(944): ReflectionClass->__construct('Illuminate\\Http...')
#1 /Users/linxi/app/live-class-service/vendor/illuminate/container/Container.php(819): Illuminate\Container\Container->build('Illuminate\\Http...')
#2 /Users/linxi/app/live-class-service/vendor/illuminate/container/Container.php(755): Illuminate\Container\Container->resolve('Illuminate\\Http...', Array)
#3 /Users/linxi/app/live-class-service/vendor/laravel/lumen-framework/src/Application.php(327): Illuminate\Container\Container->make('Illuminate\\Http...', Array)
#4 /Users/linxi/app/live-class-service/vendor/laravel/lumen-framework/src/helpers.php(42): Laravel\Lumen\Application->make('Illuminate\\Http...', Array)
#5 /Users/linxi/app/live-class-service/app/Logging/TraceIdProcessor.php(102): app('request')

  • 查看官方库,发现有两处变动,一个是/Users/linxi/app/live-class-service/vendor/illuminate/http/Concerns/InteractsWithInput.php文件的第14行,多了一个 use Dumpable, InteractsWithData;,但是InteractsWithData是在Illuminate\Support组件下,而Support组件的git仓库的最新版本也是有这个文件的。但是我们通过composer下载的时候,http模块可以拉取到最新版本,但是support模块拉取不到最新版本,导致InteractsWithData这个trait文件不存在,项目启动失败。

在这里插入图片描述

解决方案

1.我尝试升级Support到最新版本,但是有很多依赖的组件不支持

composer update illuminate/support:11.x-dev -vvv

2.我尝试降级http

 composer update illuminate/http:v11.30.0 -vvv

这种方式是可行的。

原因分析

发现其他项目是没有问题的,但是这个项目我指定下载suppot:v11.34.1的时候总是报错

composer require illuminate/support:v11.34.1 -vvv

Problem 1
    - Root composer.json requires illuminate/support v11.34.1 -> satisfiable by illuminate/support[v11.34.1].
    - illuminate/support v11.34.1 requires voku/portable-ascii ^2.0.2 -> satisfiable by voku/portable-ascii[2.0.2, 2.0.3] from composer repo (https://repo.packagist.org) but voku/portable-ascii[dev-renovate/major-github-artifact-actions, dev-renovate/codecov-codecov-action-3.x, dev-renovate/codecov-codecov-action-4.x, dev-renovate/shivammathur-setup-php-2.x, dev-dependabot/add-v2-config-file, dev-renovate/actions-cache-2.x, dev-renovate/actions-cache-4.x, dev-renovate/actions-checkout-4.x, dev-master, dev-renovate/phpunit-phpunit-11.x, dev-analysis-YjYEJG, dev-analysis-a6GjMm, 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.6.0, 1.6.1, 2.0.0, 2.0.1] from composer repo (https://xxx.com/arch/counter) has higher repository priority. The packages from the higher priority repository do not match your constraint and are therefore not installable. That repository is canonical so the lower priority repo's packages are not installable. See https://getcomposer.org/repoprio for details and assistance.
  Problem 2
    - Root composer.json requires laravel/lumen-framework ^11 -> satisfiable by laravel/lumen-framework[v11.0.0, 11.x-dev].
    - illuminate/support v11.34.1 requires voku/portable-ascii ^2.0.2 -> satisfiable by voku/portable-ascii[2.0.2, 2.0.3] from composer repo (https://repo.packagist.org) but voku/portable-ascii[dev-renovate/major-github-artifact-actions, dev-renovate/codecov-codecov-action-3.x, dev-renovate/codecov-codecov-action-4.x, dev-renovate/shivammathur-setup-php-2.x, dev-dependabot/add-v2-config-file, dev-renovate/actions-cache-2.x, dev-renovate/actions-cache-4.x, dev-renovate/actions-checkout-4.x, dev-master, dev-renovate/phpunit-phpunit-11.x, dev-analysis-YjYEJG, dev-analysis-a6GjMm, 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.6.0, 1.6.1, 2.0.0, 2.0.1] from composer repo (https://xxx.com/arch/counter) has higher repository priority. The packages from the higher priority repository do not match your constraint and are therefore not installable. That repository is canonical so the lower priority repo's packages are not installable. See https://getcomposer.org/repoprio for details and assistance.

看样子是和已有的某个包不兼容,于是我继续查找原因,看到一行

高优先级的仓库 https://xxx.com/arch/counter 中没有符合 ^2.0.2 要求的 voku/portable-ascii 版本。

最终解决

原来是私有仓库没有有voku/portable-ascii的2.0.2以上版本,我感觉很奇怪,为什么去私有仓库下载这个组件呐,于是我继续探究原因,发现是当项目中配置了私有仓库的时候,如果没有配置优先级,那么组件优先从私有仓库下载。所以,我设置了一下仓库的优先级

"repositories": {
        "counter": {
            "type": "composer",
            "url": "https:///arch/counter",
            "canonical": false

        }
  • 然后删除vendor组件和composer.lock,重新composer install ,完美解决问题
;