0

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?

asked May 16, 2021 at 22:03
5
  • Have you configured your main composer.json to know where to look for your custom package (i.e. probably as a "path" or "artifact")? getcomposer.org/doc/05-repositories.md#hosting-your-own Commented May 16, 2021 at 23:21
  • No I have not done this. So I add the path to the theme root as a repository? I'm using paths in this case. Commented May 17, 2021 at 0:19
  • I believe that you would want to configure your main composer.json by running something like: "composer config repositories.ben path app/design/frontend/ben/gotheme". This should add the relevant path repository to your main composer.json, and allow it to be found when you run "composer require". Commented May 17, 2021 at 1:23
  • I ended up adding it manually in the composer.json and running composer update. But, I see it would have been easier to just run composer require. Thank you. If you can make that into an answer I will accept. Commented May 17, 2021 at 1:37
  • I'm glad that it is working. Commented May 17, 2021 at 2:21

1 Answer 1

0

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

answered May 17, 2021 at 2:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.