0

Client has a sqldump and a tarball of a broken Drupal site.

Instead of using Composer to set up the recommended project, it looks like the previous developer performed a git checkout of http://git.drupal.org/project/drupal circa Drupal 8.6.15 :anguished:.

I'd like to Composerize the project before attempting to update Drupal from D8 to D9, but it looks like I can no longer composer require "drupal/core-recommended": :8.6.15":

$ ddev composer install
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - composer/installers v1.5.0 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.3.0] but it does not match the constraint.
    - drupal/core-recommended 8.6.15 requires composer/installers v1.5.0 -> satisfiable by composer/installers[v1.5.0].
    - Root composer.json requires drupal/core-recommended 8.6.15 -> satisfiable by drupal/core-recommended[8.6.15].

composer [install] failed, composer command failed: exit status 2. stderr=

What's the best practice here?

5
  • 1
    I think the problem may be that that site is not composer 2 compatible. Try downgrading to composer 1, and then running composer install again.
    – Jaypan
    Jan 25 at 0:03
  • Thanks @Jaypan! I must have blocked out the memories of the Composer v1 -> v2 transition. I'll try that right away! Jan 25 at 0:35
  • 2
    What's the best practice here? Have a read at the official docs, Add Composer to an existing site
    – No Sssweat
    Jan 25 at 0:46
  • I’m voting to close this question because it asks for tutorials, documentation, modules, themes, or distributions you need to find or you ask us to recommend or suggest.
    – cilefen
    Jan 25 at 12:10
  • I really think this question should be closed as in the very least it needs more focus. "Why is this specific Composer error happening?" is answerable, although it may not be on-topic for Drupal Answers as it is not specifically Drupal-related. But the best practices are published elsewhere.
    – cilefen
    Jan 25 at 15:49

1 Answer 1

1

Steps to create locally in DDEV:

mkdir testd9
cd testd9
ddev config
# defaults to: testd9, current folder, PHP
ddev composer create drupal/recommended-project:9.5.1 --no-install
nano composer.json
# change composer/installers to 1.5
# temporarily remove drupal/core-composer-scaffold to 8.6.15
# temporarily remove drupal/core-project-message to 8.6.15
# change drupal/core-recommended to 8.6.15
# save
nano .ddev/config.yaml
# change php_version to 7.4
# change composer_version to 1
# save
rm composer.lock
ddev restart
ddev composer install
ddev config
# defaults to testd9, web, drupal8
# load database
# load files folder
# test install
# upgrade to different drupal version.
# composer/installers will need to be upgraded occaisionally.
# at 8.8 it will require the drupal-core-composer-scaffold Keep in sync with drupal/core-recommended
# drupal/core-project-message is not needed.

resulting composer.json:

{
    "name": "drupal/recommended-project",
    "description": "Project template for Drupal 9 projects with a relocated document root",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": {
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "1.5",
        "drupal/core-recommended": "8.6.15"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "stable",
    "prefer-stable": true,
    "config": {
        "allow-plugins": {
            "composer/installers": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "dealerdirect/phpcodesniffer-composer-installer": true
        },
        "sort-packages": true
    },
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },
        "installer-paths": {
            "web/core": [
                "type:drupal-core"
            ],
            "web/libraries/{$name}": [
                "type:drupal-library"
            ],
            "web/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "web/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "web/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "web/profiles/custom/{$name}": [
                "type:drupal-custom-profile"
            ],
            "web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },
        "drupal-core-project-message": {
            "include-keys": [
                "homepage",
                "support"
            ],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/recommended-project template!          </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",
                "  * Install the site: https://www.drupal.org/docs/installing-drupal",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        }
    }
}
1
  • Thanks @Warped! That composer.json worked for me after setting Composer version to 1. Jan 25 at 17:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.