Composer setup does not install the plugin in the libraries folder

Created on 21 September 2020, about 4 years ago
Updated 14 July 2023, over 1 year ago

I have followed the setup guide on the project page to get composer to install the ckeditor-wordcount-plugin plugin in the libraries folder.
When I require the module, the plugin is put into the vendor folder instead.

What is going wrong? Below is the relevant part of my composer.json file:

{
    ...
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ],
    "require": {
        "composer/installers": "^1.4",
        "cweagans/composer-patches": "^1.6",
        "drupal/core": "~8.9.0",
        "drupal/core-composer-scaffold": "^8.9",
        "drupal/core-project-message": "^8.9",
        "drupal/core-vendor-hardening": "^8.9",

        ...

        "drupal/ckwordcount": "^1.1",

        ...

        "drush/drush": "^9.6.2",
        "hirak/prestissimo": "^0.3.7",
        "oomphinc/composer-installers-extender": "^1.1",
        "wikimedia/composer-merge-plugin": "^1.4",
        "zaporylie/composer-drupal-optimizations": "^1.0"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "extra": {
        "merge-plugin": {
            "include": [
                "http/modules/contrib/webform/composer.libraries.json"
            ]
        },
        "drupal-scaffold": {
            "locations": {
                "web-root": "./http/"
            }
        },
        "enable-patching": true,
        "composer-exit-on-patch-failure": true,
        "installer-paths": {
            "http/core": [ "type:drupal-core" ],
            "http/modules/contrib/{$name}": [ "type:drupal-module" ],
            "http/libraries/{$name}": [ "type:drupal-library", "w8tcha/ckeditor-wordcount-plugin", "type:bower-asset", "type:npm-asset" ]
        },
        "installer-types": [ "bower-asset", "npm-asset" ]
    }
}
📌 Task
Status

Fixed

Version

1.0

Component

Documentation

Created by

🇧🇪Belgium weseze

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand kent@passingphase.nz

    I was not able to get this working by any of the methods outlined. Instead I am using this library: https://github.com/oomphinc/composer-installers-extender and ensured that my type name is prefixed with 'drupal-'. No need for any fancy packages in repositories or anything. Just ensure that the type name used in the custom module/library is the same as the one you want to save to your custom directory:

    e.g in the module

    {
      "name": "myproject/mymodule",
      "type": "drupal-myproject-custom-module",
      ...
    }
    

    And in the root composer.json:

              "web/modules/myproject/{$name}": [
                    "type:drupal-myproject-custom-module"
               ],
    
  • 🇵🇹Portugal jcnventura

    @NewZeal, this thread is about installing the Javascript libraries required by this module, and not a custom module.

    To install a custom module, you should not need to use "oomphinc/composer-installers-extender", but can instead use the "composer/installers" library, and give your module the standard "drupal-custom-module" type. See https://www.drupal.org/docs/develop/creating-modules/add-a-composerjson-... for more information.

  • 🇳🇿New Zealand kent@passingphase.nz

    My apologies. Actually, my intention is to install in a custom folder and not the standard "drupal-custom-module", for which the solution I provided seems essential.

  • 🇵🇹Portugal jcnventura

    It's a bit off-topic, but if you are OK with installing all your drupal-custom-module in the same directory, you should be fine with the base composer/installers package, and setting the directory in https://github.com/drupal/recommended-project/blob/10.1.x/composer.json#L54

    Of course, if you want to install drupal-custom-module in web/modules/custom and some other custom module in web/modules/myproject, the yes, you need to define your own type for this drupal-myproject-custom-module cases. It does seem a bit too many levels of custom modules, but I'm pretty sure if you need that, that there are good reasons for it.

  • 🇳🇿New Zealand kent@passingphase.nz

    Yes, the reason for the custom folder is that the module has its own git repo that is made available as a package from gitlab, therefore it is not to be altered within the current repo. Meanwhile all modules under custom folder belong to the current repo and should be altered as required within the current repo.

  • 🇧🇪Belgium ludo.r Brussels

    For me it worked like this:

    Add this to composer.json

        "extra": {
            "merge-plugin": {
                "include": [
                    "[web-root]/modules/contrib/ckwordcount/composer.libraries.json"
                ]
            }
        }
    

    And then

    composer require drupal/ckwordcount and not composer require drupal/ckwordcount w8tcha/ckeditor-wordcount-plugin.

Production build 0.71.5 2024