I'm running composer 2.7.2 on a Linux Virtual Private Server hosted by GoDaddy.com.

When I do a composer diagnose, I get the message:

"Composer could not detect the root package (drupal/recommended-project) version, defaulting to '1.0.0'. See https://getcomposer.org/root-version"

I'm inferring that this is a problem and it would be good to fix it.

The message directs me to the composer troubleshooting guide and I read it, but I'm still unclear what my best course of action is.

Was the COMPOSER_ROOT_VERSION variable supposed to be set at some point, but it wasn't?

How do I find out what the right value is to set that environmental variable?  

Thanks in advance.

Comments

katorymnd’s picture

Setting it to the next logical version based on your project's history or starting with 1.0.0 if you're just beginning can work. Use the command export COMPOSER_ROOT_VERSION=x.y.z in your terminal, replacing x.y.z with your version.

combert’s picture

Is it a problem to not have a version set?

maxilein’s picture

I did not change my project. Suddenly composer 2.7.2 complains.

Where does it come from?

What needs to be set in composer.json?

Is the version referring to Drupal version?

Could you please give an example line what would be expected in the json file?

Thank you.

katorymnd’s picture

the warning is Composer's way of indicating that it's assuming your project's version in the absence of explicit information. For Drupal site development and management, this typically doesn't pose an issue for day-to-day operations, unless your project is distributed as a Composer package.

For a distributed package, a version line in composer.json might look like this (though, again, it's often unnecessary for site projects and can even be discouraged because it can conflict with VCS tagging):

{
    "name": "vendor/project-name",
    "description": "A brief description of your project",
    "version": "1.2.3",
    ...
}

To silence the warning, you could define the COMPOSER_ROOT_VERSION environment variable as a workaround, especially if you're encountering this in automated environments like CI/CD pipelines. Setting this variable to a version that reflects your project's current state.

To set this variable, you would typically use:

export COMPOSER_ROOT_VERSION=1.0.0

starting with a version that represents the state of your project (like 1.0.0 for an initial state) and incrementing it as you make significant updates is logical.

Please backup everything before making any changes.

maxilein’s picture

Thank you!

It is explicitly refering to the Drupal site project?

Or could it be caused by a module that does not specify a version?

katorymnd’s picture

now you must  deactivate each module  one by one as you clear the cache and see if the  error is, you will know what module is  causing all the  havoc and make the necessary changes to it

maxilein’s picture

There is no verbose output?

maxilein’s picture

composer update -vvv

made it clear for sure.

ulandreman’s picture

Thanks for all your suggestions and assistance.

webmestre’s picture

I'm experiencing the same issues on different hosts.

composer update -vvv

had no effect. :(

maxilein’s picture

it only gives you more information...

Then you can see if it is the ignoreble situation described above.

fred6633’s picture

I made a fresh install today "composer create-project drupal/recommended-project my_site_name" in a test directory. Directly afterwards a "composer diagnose" returned this message. So obviously it is not an additional module that causes it.

Fred

webmestre’s picture

Hi katorymnd

could you explain where do I have to use this code?

export COMPOSER_ROOT_VERSION=1.0.0
fred6633’s picture

In $HOME/.profile or $HOME/.bash_profile works. Check which you have.

webmestre’s picture

I'm sorry, I don't understand what I have to do.
Is it a path I can manage by SSH, SFTP...?
Where is inside a debian config?

fred6633’s picture

I have put the code in /home/user_me/.profile. Log in via SSH and type ls -al and you see either .profile or .bash_profile.

I don't know if my solution is proper but the message is gone.

Fred

wxman’s picture

All my sites started doing the same thing as well. I got rid of it by adding

export COMPOSER_ROOT_VERSION=dev-main

to all the sites .bashrc file.

ressa’s picture

It turns out that Add a warning message when Composer is not able to guess the root package version #11858 was too broad, causing many false positives as we have seen. It will be fixed when Only show warning about default version when not "project" type #11885 in the next release of Composer.