I'm trying to install Alpaca theme following the documentation.
I've created my composer.json file under app/design/frontend/ben/gotheme/composer.json
{
 "name": "ben/gotheme",
 "description": "",
 "type": "magento2-theme",
 "require": {
 "snowdog/theme-frontend-alpaca": "2.19.*",
 "ben/gotheme-front-tools": "*"
 },
 "autoload": {
 "files": [
 "registration.php"
 ]
 }
}
My registration.php looks like this:
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
 ComponentRegistrar::THEME,
 'frontend/ben/gotheme',
 __DIR__);
When I try to install the theme running the following command from mangeto root I get an error:
composer require ben/gotheme
The error:
[InvalidArgumentException] 
Could not find a matching version of package ben/gotheme. Check the package spelling, your 
version constraint and that the package is available in a stabili ty which matches your minimum-stability (stable). 
I'm unsure what's going here. Why is composer not finding my package? Is there something I'm missing?
1 Answer 1
I have a pretty narrow understanding of composer, so perhaps someone will add a more comprehensive response.
The issue is that the main composer.json must be configured to look for any custom package that is not hosted in the default packagist.org repository (https://getcomposer.org/doc/05-repositories.md#hosting-your-own)
This can be done by using, e.g. composer config repositories.ben path app/design/frontend/ben/gotheme
In this example "repositories.ben" sets "ben" as the repository name. The path should be the path to the directory where your package's composer.json is located. (This could also be a path to a custom module in /vendor).
Running this command will add a repository configuration to the main composer.json, such as in the following example, where it is added to the existing Magento2 repository configuration:
"repositories": {
 "0": {
 "type": "composer",
 "url": "https://repo.magento.com/"
 },
 "ben": {
 "type": "path",
 "url": "app/design/frontend/ben/gotheme"
 }
},
(It is also fine to edit composer.json directly)
Once the repository is configured, the package will be found when running, e.g. composer require ben/gotheme
composer.jsonand runningcomposer update. But, I see it would have been easier to just runcomposer require. Thank you. If you can make that into an answer I will accept.