git 请求的包...在任何版本中都找不到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40119043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:21:50  来源:igfitidea点击:

The requested package ... could not be found in any version

phpgitcomposer-php

提问by yooouuri

When I want to require my project, the following errors shows up:

当我想要求我的项目时,会出现以下错误:

The requested package mvc-php/framework could not be found in any version, there may be a typo in the package name.

在任何版本中都找不到请求的包 mvc-php/framework,包名可能有拼写错误。

The "mvc-php/framework" is a git folder.

“mvc-php/framework”是一个 git 文件夹。

{
    "name": "mvc-php/app",
    "repositories": [
        {
            "type": "path",
            "url": "/Users/youri/Documents/Github/framework"
        }
    ],
    "require": {
        "php": ">=7.0",
        "mvc-php/framework": "master"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/"
        }
    }
}

Project i want to require:

我想要求的项目:

{
    "name": "mvc-php/framework",
    "description": "PHP MVC framework",
    "autoload": {
        "psr-4": {
            "Mvc\" : "src/"
        }
    },
    "require": {
        "php": ">=7.0"
    }
}

回答by Jeff Puckett

Instead of just the branch name, you must require branchName@dev

您必须要求而不仅仅是分支名称 branchName@dev

https://getcomposer.org/doc/articles/versions.md#branches

https://getcomposer.org/doc/articles/versions.md#branches

{
    "name": "mvc-php/app",
    "repositories": [
        {
            "type": "path",
            "url": "/Users/youri/Documents/Github/framework"
        }
    ],
    "require": {
        "php": ">=7.0",
        "mvc-php/framework": "master@dev"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/"
        }
    }
}

回答by kenorb

The requested package X/Y could not be found in any version.

在任何版本中都找不到请求的包 X/Y。

The requested package needs to be a git folder with the committed and existing composer.jsonfile. Then to reference specific branch, you need to add the dev-prefix, so dev-master, not master.

请求的包需要是一个包含已提交和现有composer.json文件的 git 文件夹。然后要引用特定的分支,您需要添加dev-前缀,所以dev-master而不是master

Example

例子

Here is the minimal working example:

这是最小的工作示例:

File: composer.json

文件: composer.json

{
  "require": {
    "local/my_package": "dev-master"
  },
  "repositories": [
    {
      "packagist.org": false
    },
    {
      "type": "path",
      "url": "my_package/"
    }
  ]
}

File: my_package/composer.json

文件: my_package/composer.json

{
  "name": "local/my_package",
  "require-dev": {
    "symfony/console": "*"
  }
}

Note: Above file is under local Git repository. To create one, run: git init && git commit -am 'Files'.

注意:以上文件位于本地 Git 存储库下。要创建一个,运行:git init && git commit -am 'Files'

Troubleshooting

故障排除

To troubleshoot the issue, run:

要解决问题,请运行:

composer install -vvv

Also consider running: composer diagnoseto identify common Composererrors.

还可以考虑运行:composer diagnose以识别常见的Composer错误。

回答by amflare

As this is the first response when searching the error text on Google, I will also put my fix here, despite not being 100% relevant to the OP.

由于这是在 Google 上搜索错误文本时的第一个响应,尽管与 OP 不是 100% 相关,但我也会将我的修复放在这里。

When you are requiring the repo, you need to make sure that your requires statement matches the name of the project in the composer.json of the project.

当您需要 repo 时,您需要确保您的 requires 语句与项目的 composer.json 中的项目名称匹配。

So if the name had been "name": "mvc-php/app-framework",in the framework project, then the require would need to be:

因此,如果名称已"name": "mvc-php/app-framework",在框架项目中,则需要为:

"require": {
  "mvc-php/app-framework": "dev-master"
},

This is more applicable when you are adding a git repo. Especially when forking, as sometimes the git url might be different from the composer.json name.

当您添加 git repo 时,这更适用。特别是在分叉时,有时 git url 可能与 composer.json 名称不同。

Additionally (and this is the part relevant to OP), you now need to do dev-branch_nameinstead of branch_name@devwhen requiring. I don't know when this changed, or if the old method is unusable. But this is what the current composer docs now say.

此外(这是与 OP 相关的部分),您现在需要执行dev-branch_name而不是branch_name@dev在需要时执行。我不知道这什么时候改变了,或者旧方法是否无法使用。但这就是当前的作曲家文档现在所说的。

If you want Composer to check out a branch instead of a tag, you need to point it to the branch using the special dev-*prefix
Composer Documentation - Versions and Constraints - Branches

如果您希望 Composer 检出分支而不是标签,则需要使用特殊dev-*前缀Composer Documentation - Versions and Constraints - Branches将其指向
分支

回答by DazBaldwin

Another Gotcha to be Aware Of:

另一个需要注意的问题:

I changed the name of a package I developed and was just testing a branch on it. I had followed all the correct naming conventions mentioned above but was still getting the given error.

我更改了我开发的包的名称,只是在其上测试一个分支。我遵循了上面提到的所有正确的命名约定,但仍然出现给定的错误。

It turns out that for the name change to be picked up, you have to update the package name in composer.jsonon the main branch of the package repo (Masterfor me) even if you are not using that branch within your project.

事实证明,要获取名称更改,即使您没有在项目中使用该分支,您也必须composer.json在包 repo 的主分支上更新包名称(Master对我而言)。

回答by u10612310

It is important to note that if you do not add your own mirror source to the global variable, an error will occur where the sub-scene is not found. You can add this in composer.json:

需要注意的是,如果不将自己的镜像源添加到全局变量中,会出现找不到子场景的错误。你可以在 composer.json 中添加:

"repositories":[
 {
  "type":"composer",
  "url":"https://packag"
 }
],