Skip to content

ServiceProvider Not Found Laravel v12 #2127

@naseemkhan-netizen

Description

@naseemkhan-netizen

Provider not found error in Laravel 12 with nwidart/laravel-modules

Environment

  • PHP Version: 8.4.13
  • Laravel Version: ^12
  • Package Version: nwidart/laravel-modules ^12.0

Description

After following the setup steps for nwidart/laravel-modules, I'm still encountering a "provider not found" error when trying to use modules in Laravel 12.

getting error this again and again

php artisan

   Error 

  Class "App\Modules\Platform\Providers\PlatformServiceProvider" not found

  at vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:205
    201▕      * @return \Illuminate\Support\ServiceProvider
    202▕      */
    203▕     public function createProvider($provider)
    204▕     {
  ➜ 205▕         return new $provider($this->app);
    206▕     }
    207▕ }
    208▕ 

      +12 vendor frames 

  13  artisan:16

Configuration

Root composer.json:

{
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "App\\Modules\\": "app/Modules",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        },
        "merge-plugin": {
            "include": [
                "app/Modules/*/composer.json"
            ]
        }
    }
}

app/Modules/Platform/composer.json:

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

config/modules.php:

'namespace' => 'App\Modules',

'paths' => [
    'modules' => base_path('app/Modules'),
],

Steps to Reproduce

  1. Install package: composer require nwidart/laravel-modules
  2. Publish config: php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
  3. Add "App\\Modules\\": "app/Modules" to root composer.json autoload section
  4. Run composer dump-autoload
  5. Create module: php artisan module:make Platform

Directory Structure

├── app
│   ├── Modules
│   │   └── Platform
│   │       ├── app
│   │       │   ├── Http
│   │       │   │   └── Controllers
│   │       │   └── Providers
│   │       ├── config
│   │       ├── database
│   │       │   ├── factories
│   │       │   ├── migrations
│   │       │   └── seeders
│   │       ├── resources
│   │       │   ├── assets
│   │       │   │   ├── js
│   │       │   │   └── sass
│   │       │   └── views
│   │       ├── routes
│   │       └── tests
│   │           ├── Feature
│   │           └── Unit
│   └── Providers

Expected Behavior

Modules should be discovered and loaded without errors.

Actual Behavior

Getting "provider not found" error.

Additional Context

  • All configuration appears correct
  • composer dump-autoload has been run
  • Module structure is generated correctly by the package

Question

What additional steps or configuration am I missing to resolve this "provider not found" error in Laravel 12?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions