Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ArvinGolshani's avatar

Problem With Laravel Modules Package

Hello, I am using the laravel-modules package and I am in the process of modularizing my application.

According to the official documentation of this package

I ran the following command to install the package:

composer require nwidart/laravel-modules

The package was installed successfully.

After that, I created my first module. However, when trying to create other modules or run any Composer-related command, I get the following error:

PS E:\laravel\ReactHamgam> php artisan module:make Decisions

Error

Class "Modules\Thoughts\Providers\ThoughtsServiceProvider" not found

at vendor\laravel\framework\src\Illuminate\Foundation\Application.php:961 957▕ * @return \Illuminate\Support\ServiceProvider 958▕ / 959▕ public function resolveProvider($provider) 960▕ { ➜ 961▕ return new $provider($this); 962▕ } 963▕ 964▕ /* 965▕ * Mark the given provider as registered.

1 vendor\laravel\framework\src\Illuminate\Foundation\Application.php:893 Illuminate\Foundation\Application::resolveProvider("Modules\Thoughts\Providers\ThoughtsServiceProvider")

2 vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:75 Illuminate\Foundation\Application::register("Modules\Thoughts\Providers\ThoughtsServiceProvider")

The issue seems to be that this package creates the providers folder and the service provider file within the Modules/ModuleName/app folder, but for some reason (which I am not sure of) it expects this file to be located at:

Modules\ModuleName\Providers\ModuleServiceProvider

This path is incorrect. I’ve tried reinstalling the package multiple times and tweaking its settings in various ways, but I am still facing this issue. It seems like the package is looking for the providers folder inside the module folder, even though it creates it inside the module/app/ folder, which seems correct. I’m not sure why it expects to find the file inside the module folder.

Has anyone encountered a similar issue or knows how to resolve it?

0 likes
5 replies
ArvinGolshani's avatar

Yes, I have also added this code to my composer.json:

"extra": { "laravel": { "dont-discover": [] }, "merge-plugin": { "include": [ "Modules/*/composer.json" ] } }

I also ran composer dump-autoload, deleted the bootstrap/cache/modules.php and services.php files, and cleared Laravel's configuration cache.

Additionally, even though the documentation states that "Modules\": "modules/" is no longer needed from version 11 onwards, I tried both with and without it in autoload.psr-4, but the issue still persists.

Do you have any other suggestions?

RemiM's avatar

I just tried it locally on a fresh Laravel 11 installation and didn’t encounter any issues. However, when you ran the command to install the package, did you allow it to:

execute code wish to enable it now?

For context, at one point, it prompts you with the following question, to which I responded withy:

Do you trust "wikimedia/composer-merge-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
  - Installing wikimedia/composer-merge-plugin (v2.1.0): Extracting archive
  - Installing nwidart/laravel-modules (v11.1.8): Extracting archive
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

From there, I simply added that part in the extra entry of the composer.json:

 "merge-plugin": {
        "include": [
            "Modules/*/composer.json"
        ]
    }

And run:

composer dump-autoload

Any module creation was working as expected using the command:

php artisan module:make [moduleName]
ArvinGolshani's avatar

Yes, I just tested it locally on a fresh Laravel 11 installation, and I figured out the problem. It was caused by the composer-merge-plugin. In the composer.json file, this line:

"wikimedia/composer-merge-plugin": true

was set to false. Because of that, the modules weren’t loaded. After changing it to true, the problem was solved.

Thank you!

Please or to participate in this conversation.