Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnexpectedValueException Could not parse version constraint mybranch: Invalid version string "mybranch"

I'm trying to develop a PHP library (called foo/bar) using Composer in dir /work/a with the composer.json contents:

{
    "name": "foo/bar",
    "require": {
        "php": ">=7.2"
    }
}

/work/a is a git project and I'm on the branch mybranch

I'm trying to use this lib in another project locally (called testing/foobar) using Composer in dir work/b with the composer.json contents:

{
    "name": "testing/foobar",
    "type": "project",
    "repositories": [
        {
            "type": "vcs",
            "url": "/work/a"
        }
    ],
    "require": {
        "php": "^7.4",
        "foo/bar": "mybranch"
    }
}

When running $ composer install in /work/b I get the error:

[UnexpectedValueException]                                            
  Could not parse version constraint mybranch: Invalid version string "mybranch"  
like image 252
Catfish Avatar asked Nov 23 '25 14:11

Catfish


1 Answers

You have to prefix your branch name with dev-, so your branch name will have to be dev-mybranch.

Loading a package from a VCS repository

...
In composer.json, you should prefix your custom branch name with "dev-".
...

Also check this Q/A "Composer require branch name".

Change branch name to have dev- prefix, add it to /work/b project:

{
    "name": "testing/foobar",
    "type": "project",
    "repositories": [
        {
          "type": "vcs",
          "url": "/work/a"
        }
    ],
    "require": {
        "php": "^7.4",
        "foo/bar": "dev-mybranch"
    }
}

Run composer install:

❯ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing foo/bar (dev-mybranch 85c97b7): Cloning 85c97b7b23 from cache
Writing lock file
Generating autoload files
like image 200
Christos Lytras Avatar answered Nov 25 '25 02:11

Christos Lytras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!