I'm trying to create and configure a Drupal 8.x website and I'm finding that contributed modules and or their functionality are hit-and-miss... This isn't unexpected but from a Drupal Org standpoint, what I wasn't prepared for is seeing on every module download page inadequate Composer instructions meant to help developers download and install respective modules. After all, Composer is supposed to make everything easier to maintain, right? If so, why are the "composer require" commands listed on the module download pages also hit-and-miss?
The error in Composer that I see when the "composer require" instructions listed on the module download pages fails, is as follows:
[InvalidArgumentException]
Could not find package drupal/X in a version matching N
I'm not sure what this means exactly other than to assume that the module maintainer or developers haven't used a Drupal repository... Is that correct? If so, is there a standard procedure one must use to figure out what the correct repository is? If module maintainers or developers want nothing to do with using Composer, then why are those instructions on their module download pages?
Any insight into this would be appreciated.
Comments
Comment #2
cilefen commentedIt is virtually impossible to provide assistance without seeing the composer.json file. Please post it. We will also require the precise command that fails, and a reference to which module this is.
Comment #3
wolf_22 commented@cilefen, sure thing.
Here's my composer.json file:
The requires listed above worked perfectly fine but as an example, 2 contributed modules I tried to install without any luck are the v8 alpha versions of "commerce_license" and "acl". The commands I tried to use are those listed on each of those pages I linked to $ composer require drupal/commerce_license:^2.0 and $ composer require drupal/acl:^1.0. Both commands result in the aforementioned error above...
Is this just a case of needing to add an additional repository into my composer.json file? If so, what's the standard method of determining what that additional repository entry is besides posting in each contributor's issue queue? Seems reasonable to think that if the "composer create-project --no-install..." command created the initial composer.json file, that it would have the respective repository(ies) necessary for any Drupal developer to need, especially if contributor module pages are listing generic "composer require" instructions for people to use without specific information necessary to correct deficient commands.
There were other modules that this situation has happened with, but another thing I'm seeing is how sometimes the commands work only until during the execution of the install command we're prompted for authentication details with nothing on the module download pages nor instructions indicating what these are. I understand why someone wants or needs a gated repository but to post on a module download page instructions for using Composer to download a module without first providing insights into understanding that the respective version in question exists within a gated repository, seems odd or counterproductive to how Drupal has always provided open access to those modules found from contributor download pages.
(I'm sure I'm either just misunderstanding or overlooking something here, so any insight into this would be appreciated and apologies in advance for any headaches.)
Comment #4
cilefen commentedI can't reproduce the bug you are reporting.
I created the composer.json as above, then:
No. The correct and only needed repository is set.
I am curious as to the version of Composer.
Comment #5
wolf_22 commentedIt looks like I have the following:
So I updated it...
To verify the new version, I checked it again:
And even after using a new CMD window with this newest version, I still see the error when trying to download ACL:
composer require drupal/acl:^1.0...which results in...
Any other ideas? I'm at a loss.
Comment #6
cilefen commentedHave you executed Composer in verbose mode (-vvv)?
Comment #7
cilefen commentedAlso
composer clear-cache.Comment #8
wolf_22 commentedJust tried that. Here's how it went (ultimately ended in the same outcome but I hope you can see something from everything I logged below):
1.) Executed --version:
Composer version 1.10.6 2020-05-06 10:28:102.) Executed clear-cache:
3.) Executed require acl with -vvv:
Seems like it gets to the writing of p-provider-latest.json into cache before the invalid argument ending / exception trace...
Comment #9
longwaveIs the ^ being ignored for some reason? It's not present in your error message:
Note that when I ask for ^2.0 it's shown in the error; in your example it is not shown, which makes me think Composer is looking for the exact version "1.0" - which doesn't exist.
Comment #10
longwaveOn Windows it seems the caret is ignored, sometimes: https://github.com/composer/composer/issues/5151
Comment #11
wolf_22 commentedNice eyes, longwave...but on that github thread you linked to, it sounds like it's only an issue for a 64-bit Windows 7 architecture (and not a Windows 10 system like the one I was trying all this from). I could be wrong...
In any event, I'll try to poke a stick at different command formats to see if it helps any, such as quoting things or using the double-caret approach like one of the commenters claimed to have worked. Out of curiosity, how does one learn what versions are available for someone to use in their Composer command? Because I just looked at their repository but I'm not sure what constitutes a version that can be used in Composer unless the standard practice is that you just imply for Composer that you want a version higher than X via things like tildes or carets, etc...all I see are more human-readable version identifiers, such as "8.x-1.0-alpha2." Does each Git repo have an explicit page somewhere that divulges this kind of information?
Comment #12
cilefen commentedcomposer show -a package/namehttps://getcomposer.org/doc/03-cli.md#show
Comment #13
wolf_22 commentedThanks for the command, cilefen.
So I finally managed to get everything downloaded... I used the quadruple caret approach as follows:
composer require drupal/acl:^^^^1.0Using the same approach, I also managed to get the current content_access downloaded this way, too:
composer require drupal/content_access:^^^^1.0Everything is showing up as expected in the composer.json file, the module(s) have been downloaded, and I'm seeing interfaces in my Drupal installation after installing both... Totally nuts but I'm happy it's working now.
Thanks you two!
Comment #14
longwaveGlad you were able to resolve it, thanks for following up with the fix as it will help others if they have the same issue.
Comment #15
cilefen commentedComment #16
cilefen commentedComment #18
hockey2112 commented#13 worked for me:
composer require drupal/views_simple_math_field:^^^^2.0@beta
Comment #19
ugintl commentedCan someone answer this https://drupal.stackexchange.com/questions/305467/composer-require-insta...
Comment #20
fvictoire commentedVersion 9.3.3
#13 worked well for me
composer require 'drupal/flysystem:^^^^2.0@beta'