1

I have installed Drupal 8 on Ubuntu. All works well, but I cannot create a new module using Drupal Console.

When I run drupal generate:module, I get the following error message.

[InvalidArgumentException]
Module path "/var/www/html/maryem/modules/custom" is invalid. You need to provide a valid path.

Why? How can I avoid that error message?

3

There is no such thing as modules/contrib or modules/custom with the vanilla download of Drupal.

It is a convention you can use for organization. Create the folders yourself. Drupal will still find the modules in either one. The same principle applies to the themes folder. Some modules that say "download the JS plugin to /libraries" - you would have to create this folder too.

Drush, Drupal Console, and Composer all understand this, as well. If you are using Composer, you just need to inform it in your root composer.json, example:

    "installer-paths": {
        "docroot/core": [
            "type:drupal-core"
        ],
        "docroot/modules/contrib/{$name}": [
            "type:drupal-module"
        ],
        "docroot/modules/custom/{$name}": [
            "type:drupal-custom-module"
        ],
        "docroot/profiles/contrib/{$name}": [
            "type:drupal-profile"
        ],
        "docroot/profiles/custom/{$name}": [
            "type:drupal-custom-profile"
        ],
        "docroot/themes/contrib/{$name}": [
            "type:drupal-theme"
        ],
        "docroot/themes/custom/{$name}": [
            "type:drupal-custom-theme"
        ],
        "docroot/libraries": [
            "type:drupal-library"
        ],
        "drush/contrib/{$name}": [
            "type:drupal-drush"
        ]
    }

When requiring modules, profiles, or themes, Composer will then place them in the appropriate directory.

0

Use chown to change ownership and chmod to change rights.

example: sudo chown -R username:group directory thks !

-1

Old issue still the answer is missing. The path needs to exist before running the console command. The error message means that "/var/www/html/maryem/modules/custom" does not exist. Options:

  1. Provide the correct path when the folder does exist
  2. Create all the directories in the path in /var/www/html/maryem/modules/custom For instance when custom is missing it should be created in /var/www/html/maryem/modules before I run de console command.

In my case I provided --module-path=/modules/custom which expects to find it in the root of the server. Since I was running the console command in the web server document root of Drupal, I should have used a relative path like this --module-path=modules/custom or a correct absolute path like you did in your example.

  • I don't think you have to create the folders. Console generate will create the folder - be it the folder for the module or the last directory name. I gave a path modules/custom2 and it created custom2 inside modules folder and created the module inside custom2. At the same time if I give modules2/custom2 then it gives an error. So yes the path should be present except for the last directory. – anoopjohn Oct 16 '19 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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