skip to Main Content

Class "ModulesAdminModuleProvidersAdminModuleServiceProvider" not found is an error I’m encountering when I create a module in Laravel called AdminModule.

When I attempted to utilize the composer dump auto-load command, I also encountered issues like

Script @php artisan package:discover –ansi handling the post-autoload-dump event returned with error code 1

2

Answers


  1. Check the composer auto-load. If you think all autoloads are correct, send your composer.

    Login or Signup to reply.
  2. The error you’re encountering mostly occurs when Laravel cannot find the class or file for your module’s service provider due to one of the following issues:

    1. Namespace misalignment
      Make sure the namespace in your AdminModuleServiceProvider matches the
      directory structure and the module’s PSR-4 autoload configuration in composer.json.
    namespace ModulesAdminModuleProviders;
    
    use IlluminateSupportServiceProvider;
    
    class AdminModuleServiceProvider extends ServiceProvider
    
    {
        
    public function register()
        {
            // Register services
        }
    
        public function boot()
        {
            // Bootstrap services
        }
    }
    
    • If your file is located at Modules/AdminModule/Providers/AdminModuleServiceProvider.php, the namespace must match ModulesAdminModuleProviders.
    • Composer AutoLoading
    • If you created the module manually, ensure your composer.json file includes the module’s namespace in the autoload section:
        "autoload": {
            "psr-4": {
                "Modules\AdminModule\": "Modules/AdminModule/"
            }
        }
    
    • After editing composer.json, run:
        composer dump-autoload
    
    1. Module Discovery
    • Verify that the module is registered in the Laravel application’s config/app.php (if applicable) or modules_statuses.json file:
        {
            "Modules\AdminModule\": true
        }
    
    1. Fixing the package:discover Issue
    • Run composer dump-autoload again, ensuring no syntax or path errors exist in the project.
    • If the issue persists:
      • Check composer.json for post-autoload scripts that might be failing:

         "scripts": {
        "post-autoload-dump": [
            "@php artisan package:discover --ansi"
          ]
        }
        
    • Manually run the failing command to see the specific error:
        php artisan package:discover
    
    1. Clearing Laravel Caches
    • Laravel may cache the service provider or autoloaded files. Clear the caches to refresh:
        php artisan config:clear
        
        php artisan cache:clear
        
        php artisan route:clear
        
        php artisan clear-compiled
        
        php artisan optimize
    

    Debugging Steps

    1. Verify the file path for AdminModuleServiceProvider.php.
    2. Ensure the class name and namespace are correctly defined.
    3. Check the autoload configuration in composer.json.
    4. Run the following commands sequentially:
        composer dump-autoload
        
        php artisan package:discover
        
        php artisan config:clear
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search