PHP8 下由于 psr/container 安装数据库扩展失败的问题

fenger

问题描述

新建的webman项目,根据官方文档,安装数据库扩展报错

官方文档安装数据库扩展命令
官方文档:https://www.workerman.net/doc/webman/db/tutorial.html

// 创建Webman项目
composer create-project workerman/webman Test
// 进入项目目录
cd Test
// 安装数据库扩展
composer require -W psr/container ^1.1.1 illuminate/database illuminate/pagination illuminate/events symfony/var-dumper

// 报错内容
In PackageDiscoveryTrait.php line 361:

  Could not find package windows.php.

  Did you mean one of these?
      skjob/wkhtmltopdf-windows
      issetbv/push-notification
      clevis/push-notifications
      fishmad/wkhtmltopdf-windows
      lifewatch/wkhtmltopdf-windows

require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>...]

电脑环境

  • macOS 12.6
  • PHP 8.1.9
  • Composer 2.5.5

解决方式

安装数据库扩展时,如下去除 psr/container 的版本指定即可

composer require -W psr/container illuminate/database illuminate/pagination illuminate/events symfony/var-dumper

找了很久问题,发现在创建webman项目的时候,已经安装了 psr/container (2.0.2) ,而官方文档里安装数据库扩展命令里,还指定的psr/container 为1.1.1版本,所以尝试 去除版本指定 就安装成功了

composer create-project workerman/webman Test
Creating a "workerman/webman" project at "./Test"
Info from https://repo.packagist.org: #StandWithUkraine
Installing workerman/webman (v1.5.1)
  - Installing workerman/webman (v1.5.1): Extracting archive
Created project in /Users/Jayden/Documents/Dev/SourceCode/PHP/laravel/Code/Webman/Test
Loading composer repositories with package information
Updating dependencies
Lock file operations: 6 installs, 0 updates, 0 removals
  - Locking monolog/monolog (2.9.1)
  - Locking nikic/fast-route (v1.3.0)
  - Locking psr/container (2.0.2)
  - Locking psr/log (3.0.0)
  - Locking workerman/webman-framework (v1.5.4)
  - Locking workerman/workerman (v4.1.9)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 6 installs, 0 updates, 0 removals
  - Installing psr/log (3.0.0): Extracting archive
  - Installing monolog/monolog (2.9.1): Extracting archive
  - Installing workerman/workerman (v4.1.9): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing nikic/fast-route (v1.3.0): Extracting archive
  - Installing workerman/webman-framework (v1.5.4): Extracting archive
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
> support\Plugin::install
Create start.php
Create windows.php
Create support/bootstrap.php
Create support/helpers.php
14 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
2 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found

可能是因为我的电脑是PHP8,下载Laravel的组件都是最新V10版本,而 psr/container 1.1.1 最高只支持到 Laravel V9版本的原因,建议walkor 大佬可以把文档中的^1.1.1去掉

---- 更新 ----
walkor大佬讨论了下,应该不是Laravel V10版本的原因。具体原因不清楚。如果有遇到这个问题的人,可以尝试下上面的解决方式

664 1 0
1个回答

walkor
Could not find package windows.php.

composer require -W psr/container ^1.1.1 导致依赖 package windows.php 第一次见,猜测是你本地环境问题,不具有普遍性。

psr/container 1.1.1 支持最新的laravel 10数据库,目前看没有去掉的必要。去掉的话会导致一些不支持 psr/container 2的组件无法安装,到时候会有更多的人发帖提问,我还是要改回去。psr/container ^1.1.1的依赖就是之前很多人发帖反馈 psr/container 2依赖问题才加进去的。

  • walkor 2023-03-30

    你用 psr/container 2 就行了 ,碰到有需要1.1的组件时再安装

  • fenger 2023-03-30

    好的,多谢大佬

年代过于久远,无法发表回答
🔝