laravel-modules icon indicating copy to clipboard operation
laravel-modules copied to clipboard

autoloading Providers in laravel11x issue on github action composer install

Open mauritskorse opened this issue 1 year ago • 13 comments

After upgrading to laravel 11.x I adjusted the composer.json according to the upgrading docs. When building locally (using sail) everything works fine. However when pushing to my server through github actions the following fails:

RUN composer install --no-dev --ignore-platform-reqs --no-interaction --prefer-dist --no-plugins --optimize-autoloader

It returns the following error:

In ProviderRepository.php line 206:                                                              
Class "Modules\Admin\Providers\AdminServiceProvider" not found  
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Reverting the following change back fixes this issue:

     "autoload": {
         "psr-4": {
             "App\\": "app/",
-            "Modules\\": "modules/", <-- delete this
             "Database\\Factories\\": "database/factories/",
             "Database\\Seeders\\": "database/seeders/"
         }

I have tried a different approach on the composer install, but no success so far. Any other suggestions?

mauritskorse avatar Aug 21 '24 13:08 mauritskorse

Hi, @mauritskorse

To load the module with the package wikimedia/composer-merge-plugin, don't use the --no-plugins option in your install command. Remove that option and try running the command again.

alissn avatar Aug 21 '24 17:08 alissn

Sadly I have exactly same issue

  • Create new Laravel 11
  • Install Modules
  • Publish provider . No config changing
  • Create Module : Core
  • Create second module : Client

Class "Modules\Core\Providers\CoreServiceProvider" not found

at vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:206

soulevilx avatar Aug 22 '24 02:08 soulevilx

After upgrading to laravel 11.x I adjusted the composer.json according to the upgrading docs. When building locally (using sail) everything works fine. However when pushing to my server through github actions the following fails:

RUN composer install --no-dev --ignore-platform-reqs --no-interaction --prefer-dist --no-plugins --optimize-autoloader

It returns the following error:

In ProviderRepository.php line 206:                                                              
Class "Modules\Admin\Providers\AdminServiceProvider" not found  
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Reverting the following change back fixes this issue:

     "autoload": {
         "psr-4": {
             "App\\": "app/",
-            "Modules\\": "modules/", <-- delete this
             "Database\\Factories\\": "database/factories/",
             "Database\\Seeders\\": "database/seeders/"
         }

I have tried a different approach on the composer install, but no success so far. Any other suggestions?

I have fixed w/ below extra "extra": { "laravel": { "dont-discover": [] }, "merge-plugin": { "include": [ "composer.local.json", "Modules/*/composer.json" ], "recurse": true, "replace": false, "ignore-duplicates": false, "merge-dev": true, "merge-extra": false, "merge-extra-deep": false, "merge-replace": true, "merge-scripts": false } },

soulevilx avatar Aug 22 '24 02:08 soulevilx

Hi @soulevilx,

Based on the source code, after creating a new module, the command composer dump-autoload is automatically run. However, if you still encounter issues, please try running composer dump-autoload manually to ensure everything is loaded correctly.

If you continue to experience problems, please let me know.

Reference: https://github.com/nWidart/laravel-modules/blob/b51e39ce8283b118349bcc8510205020a8539080/src/Commands/Make/ModuleMakeCommand.php#L56-L61

alissn avatar Aug 22 '24 10:08 alissn

I don't have "Modules\\": "modules/" in my composer.json but still having the same issue.

adelkedjour avatar Aug 28 '24 13:08 adelkedjour

I had same issue that solved by these steps : run : php artisan clear //to clear bootstrap
adding this exact syntax (attention merge-plugin is inside extra ) into composer.json "extra": { "laravel": { "dont-discover": [] }, "merge-plugin": { "include": [ "Modules/*/composer.json" ] } }, then composer du //dump-autoload command then create your module : php artisan module:make Posts then re run composer du

mahdimirhendi avatar Sep 02 '24 23:09 mahdimirhendi

it's bugs, I can't work with modules (

ProsspaTUN avatar Sep 04 '24 08:09 ProsspaTUN

The solution for me, I don't know if it's right.

But you need to remove the provider registry in modules.json

And move provider it to bootstrap/providers.php

You need to explicitly specify the provider and correct the namespace

Снимок экрана 2024-09-04 в 13 01 55

UPD!!!

I'm stupid, in short, the module MUST have composer.json That's why it complains that it can't load the provider!

ProsspaTUN avatar Sep 04 '24 10:09 ProsspaTUN

Hi @ProsspaTUN,

Could you create a new demo project that reproduces this issue and push it to GitHub? This will help me better understand and diagnose the problem.

Thanks!

alissn avatar Sep 04 '24 15:09 alissn

The same issue for me. Any solutions here doesn't help me ( Generating optimized autoload files Class Modules\Auth\Database\Seeders\AuthDatabaseSeeder located in ./Modules/Auth/database/seeders/AuthDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping. Class Modules\Auth\App\Providers\AuthServiceProvider located in ./Modules/Auth/app/Providers/AuthServiceProvider.php does not comply with psr-4 autoloading standard. Skipping. Class Modules\Auth\App\Providers\RouteServiceProvider located in ./Modules/Auth/app/Providers/RouteServiceProvider.php does not comply with psr-4 autoloading standard. Skipping. Class Modules\Auth\App\Providers\EventServiceProvider located in ./Modules/Auth/app/Providers/EventServiceProvider.php does not comply with psr-4 autoloading standard. Skipping.

AratKruglik avatar Sep 09 '24 07:09 AratKruglik

alissn Снимок экрана 2024-09-11 в 10 18 48 The modules must contain this file, that solution for me

ProsspaTUN avatar Sep 11 '24 07:09 ProsspaTUN

compose.json must contain for next code

Example:

{ "name": "nwidart/profile", "description": "", "authors": [ { "name": "Nicolas Widart", "email": "[email protected]" } ], "extra": { "laravel": { "providers": [], "aliases": {

        }
    }
},
"autoload": {
    "psr-4": {
        "Modules\\Profile\\": "app/",
        "Modules\\Profile\\Database\\Factories\\": "database/factories/",
        "Modules\\Profile\\Database\\Seeders\\": "database/seeders/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Modules\\Profile\\Tests\\": "tests/"
    }
}

}

ProsspaTUN avatar Sep 11 '24 07:09 ProsspaTUN

After upgrading to laravel 11.x I adjusted the composer.json according to the upgrading docs. When building locally (using sail) everything works fine. However when pushing to my server through github actions the following fails:

RUN composer install --no-dev --ignore-platform-reqs --no-interaction --prefer-dist --no-plugins --optimize-autoloader

It returns the following error:

In ProviderRepository.php line 206:                                                              
Class "Modules\Admin\Providers\AdminServiceProvider" not found  
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Reverting the following change back fixes this issue:

     "autoload": {
         "psr-4": {
             "App\\": "app/",
-            "Modules\\": "modules/", <-- delete this
             "Database\\Factories\\": "database/factories/",
             "Database\\Seeders\\": "database/seeders/"
         }

I have tried a different approach on the composer install, but no success so far. Any other suggestions?

I have fixed w/ below extra "extra": { "laravel": { "dont-discover": [] }, "merge-plugin": { "include": [ "composer.local.json", "Modules/*/composer.json" ], "recurse": true, "replace": false, "ignore-duplicates": false, "merge-dev": true, "merge-extra": false, "merge-extra-deep": false, "merge-replace": true, "merge-scripts": false } },

I corrected the error using this extra as well, thanks

edeoliv avatar Sep 11 '24 15:09 edeoliv

This issue is marked as closed but I encountered this issue today (v11.1.7).

Seems to be an issue with PSR auto-loading. Resolved it by moving the folders in {module}/app (Http and Providers) into the modules root directory and changing the psr4 autoload to the root directory in the module's composer.json.

Modules/{module}/composer.json:

    "autoload": {
        "psr-4": {
            "Modules\\Module\\": "",
            "Modules\\Module\\Database\\Factories\\": "database/factories/",
            "Modules\\Module\\Database\\Seeders\\": "database/seeders/"
        }
    },

The following warning will still be encountered on composer dump-autoload though:

Class Modules\Module\Database\Seeders\ModuleDatabaseSeeder located in [...]/Modules\Module\database\seeders\ModuleDatabaseSeeder.php does not comply with psr-4 autoloading standard. Skipping.                                                                                                                   

ben-steve-sc avatar Dec 22 '24 16:12 ben-steve-sc

Maybe this would help someone: https://github.com/nWidart/laravel-modules/issues/2008#issuecomment-2603720362

freescout-help avatar Jan 21 '25 05:01 freescout-help