The requested package ... could not be found in any version
Composer's error message, "The requested package mvc-php/framework could not be found in any version," is one of the most common stumbling blocks when integrating local development tools into a production-ready project. It usually appears when you try to require a package that lives on your hard drive rather than in the public Packagist repository. The specific scenario here involves attempting to autoload a custom MVC framework from a git folder while defining it as a dependency in composer.json.
The root cause lies in how Composer resolves dependencies. When you specify "mvc-php/framework": "master" in your require section, Composer expects to find a release tag or a commit within the public repository for that package name. However, your configuration defines a private path repository pointing to /Users/youri/Documents/Github/framework. This creates a conflict: Composer is looking for the package on Packagist (or another remote source), but you are telling it to look locally.
To resolve this, you must explicitly tell Composer to treat the local git folder as the source of truth for that specific version. The solution requires adjusting the repositories and require sections in your project's composer.json.
Configuring Path Repositories Correctly
In your main application (mvc-php/app), the current configuration lists a path repository but fails to link it correctly to the dependency requirement. You need to ensure the package name matches exactly between the local source and the requirement.
Update your composer.json as follows:
{
"name": "mvc-php/app",
"repositories": [
{
"type": "path",
"url": "/Users/youri/Documents/Github/framework"
}
],
"require": {
"php": ">=7.0",
"mvc-php/framework": "^1.0"
},
"autoload": {
"psr-4": {
"Mvc\\": "../Documents/Github/framework/src"
}
}
}
There are a few critical adjustments here. First, the require version constraint should generally avoid raw branch names like "master" unless that is explicitly supported by your remote registry. Instead, use a caret constraint (^1.0) or omit the version if you strictly want the latest from the path repository. More importantly, the autoload section in your main app needs to point to the correct PSR-4 namespace and file paths relative to your project root. Since the framework defines its namespace as Mvc\\, your application's autoloader must map that namespace to the src/ directory inside the local framework folder.
Handling Local vs. Remote Disambiguation
If your local git repository does not contain a composer.json with the name "mvc-php/framework", Composer will still fail to recognize it even if the path is correct. The local package must declare its own identity. Open the composer.json inside /Users/youri/Documents/Github/framework and ensure it looks like this:
{
"name": "mvc-php/framework",
"description": "PHP MVC framework",
"autoload": {
"psr-4": {
"Mvc\\": "src/"
}
},
"require": {
"php": ">=7.0"
}
}
Without this declaration, Composer treats the directory as an unversioned path with no identifiable name, leading to the "could not be found in any version" error. The name inside the local composer.json must match exactly what you require in your main project.
Why This Matters for Workflow
This setup is common when building a framework alongside its examples or applications. It allows you to iterate on the framework code without pushing changes to Packagist immediately. However, there are trade-offs. Using path repositories ties your application strictly to the local file system. If you move the framework folder, update permissions, or run Composer on a different machine (like CI/CD), the absolute path /Users/youri/Documents/Github/framework will break unless you use a relative path or environment variable.
Additionally, relying on path repositories for development can lead to confusion if you accidentally commit the vendor folder containing the local dependency into your repository. The vendor folder should always be excluded via .gitignore.
For teams moving from local prototypes to shared libraries, this transition often requires promoting the local package to a private Packagist repository or a public GitHub Packages registry once it's stable. Until then, keeping the path repository configured correctly ensures that your local development environment remains functional and your autoloader can resolve the Mvc\\ namespace without errors.
If you need guidance on setting up more complex monorepo structures or managing private package repositories for larger teams, resources like https://laravelcompany.com offer insights into modern PHP project architectures that scale beyond simple path references.