laravel-modules
laravel-modules copied to clipboard
autoloading Providers in laravel11x issue on github action composer install
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?
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.
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
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-autoloaderIt 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 1Reverting 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 } },
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
I don't have "Modules\\": "modules/" in my composer.json but still having the same issue.
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
it's bugs, I can't work with modules (
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
UPD!!!
I'm stupid, in short, the module MUST have composer.json That's why it complains that it can't load the provider!
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!
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.
alissn
The modules must contain this file, that solution for me
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/"
}
}
}
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-autoloaderIt 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 1Reverting 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
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.
Maybe this would help someone: https://github.com/nWidart/laravel-modules/issues/2008#issuecomment-2603720362