You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Composer安装Magento 2.4.5报错:无法找到project-community-edition 2.4.5包

Magento 2.4.5安装报错:Could not find package project-community-edition with version 2.4.5

问题详情

在C:\xampp\htdocs目录执行以下命令安装Magento 2.4.5时:

composer create-project --repository-url=https://repo.magento.com/ project-community-edition:2.4.5

返回错误提示:

Could not find package project-community-edition with version 2.4.5.

当前目录下的composer.json内容:

{
    "name": "mycompany/sample-module-minimal",
    "description": "A module that creates a page in the Magento admin area",
    "type": "magento2-module",
    "version": "2.4.5",
    "license": [
      "OSL-3.0",
      "AFL-3.0"
    ],
    "require": {
      "php": "~8.2.0"
    },
    "repositories": [
        {
            "type": "composer",
           "url": "https://repo.magento.com/"
       }
   ],
    "autoload": {
      "files": [ "registration.php" ],
      "psr-4": {
        "MyCompany\\ExampleAdminNewPage\\": ""
      }
    }
  }

解决方案

1. 修正包名前缀

你使用的包名不完整,Magento社区版的正确包名为magento/project-community-edition,遗漏magento/前缀是导致找不到包的直接原因。

2. 切换到空目录执行安装

当前目录下已有一个Magento模块的composer.json,会干扰create-project的执行逻辑。请:

  • 删除当前目录下的composer.json、registration.php等模块文件;
  • 或新建空目录(如C:\xampp\htdocs\magento2),进入该目录后再执行安装命令。

3. 使用正确的安装命令

修正后的完整命令示例(指定安装目录为magento2):

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition:2.4.5 ./magento2

4. 调整PHP版本兼容性

Magento 2.4.5不支持PHP 8.2,兼容版本为7.4.x或8.1.x,请切换到符合要求的PHP版本后再执行安装。

5. 验证仓库访问密钥

确保已配置有效的Magento市场访问密钥:

  • 全局配置密钥命令:
    composer config -g repo.magento.com.username <你的公钥>
    composer config -g repo.magento.com.password <你的私钥>
    
    密钥可在Magento市场账户设置中获取,无效密钥会导致无法访问私有仓库资源。

内容的提问来源于stack exchange,提问作者Kumar Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 01:52:40