Illuminate\Contracts\Container\BindingResolutionException - Target class [CommandMakeCommand] does not exist
Asked Answered
I

10

13

Using Laravel 8.75 and trying to upgrade to php 8.1 in composer.json to "php": "^8.1" and receive the error of Illuminate\Contracts\Container\BindingResolutionException - Target class [CommandMakeCommand] does not exist.

Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. 
Use symfony/mailer instead.
Generating optimized autoload files
 
Illuminate\Foundation\ComposerScripts::postAutoloadDump
@php artisan package:discover --ansi

Illuminate\Contracts\Container\BindingResolutionException

Target class [CommandMakeCommand] does not exist.

at 

vendor/laravel/framework/src/Illuminate/Container/Container.php:879

875▕
876▕         try {
877▕             $reflector = new ReflectionClass($concrete);
878▕         } catch (ReflectionException $e) {
879▕             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
880▕         }
881▕
882▕         // If the type is not instantiable, the developer is attempting to resolve
883▕         // an abstract type such as an Interface or Abstract Class and there is

  +13 vendor frames
 14  artisan:37
 Illuminate\Foundation\Console\Kernel::handle()
Script @php artisan package:discover --ansi handling the post-autoload- 
dump event returned with error code 1
Indore answered 12/2, 2022 at 0:19 Comment(1)
What have you tried to resolve the problem? Where are you stuck? Keep in mind that Laravel 8.75 is not the latest version, so maybe updating could already help?Besmirch
I
19

i also had same problem, in my case nwidart/laravel-modules package upgraded to 8.3 version, i downgraded to 8.2 version and problem solved

Irita answered 12/2, 2022 at 17:11 Comment(4)
I am also getting same issue on few application on laravel 8 since last 2 days and still it is not fixed. I also have nwidart/laravel-modules package and it is 8.2 and has not upgraded , I am using laravel 8.40. any one have idea about it ?Tamper
remove composer.lock and vendor folder (maybe laravel-modules upgreaded in composer.lock file), and in composer.json fix laravel-modules to 8.2, "nwidart/laravel-modules": "8.2",Irita
Downgrading to 8.2 worked for me as well.Koger
Yes, replaced ^8.2 to 8.2 in composer.json file and ran composer update. Fixed the issue, thanks @Farhad!Nutter
O
9

see here: https://docs.laravelmodules.com/v9/introduction

If you have an existing config file, and you get an error:

Target class [CommandMakeCommand] does not exist

Then the config file will need updating first import the commands class:

use Nwidart\Modules\Commands;

Next replace the commands array with:

'commands' => [
    Commands\CommandMakeCommand::class,
    Commands\ComponentClassMakeCommand::class,
    Commands\ComponentViewMakeCommand::class,
    Commands\ControllerMakeCommand::class,
    Commands\DisableCommand::class,
    Commands\DumpCommand::class,
    Commands\EnableCommand::class,
    Commands\EventMakeCommand::class,
    Commands\JobMakeCommand::class,
    Commands\ListenerMakeCommand::class,
    Commands\MailMakeCommand::class,
    Commands\MiddlewareMakeCommand::class,
    Commands\NotificationMakeCommand::class,
    Commands\ProviderMakeCommand::class,
    Commands\RouteProviderMakeCommand::class,
    Commands\InstallCommand::class,
    Commands\ListCommand::class,
    Commands\ModuleDeleteCommand::class,
    Commands\ModuleMakeCommand::class,
    Commands\FactoryMakeCommand::class,
    Commands\PolicyMakeCommand::class,
    Commands\RequestMakeCommand::class,
    Commands\RuleMakeCommand::class,
    Commands\MigrateCommand::class,
    Commands\MigrateRefreshCommand::class,
    Commands\MigrateResetCommand::class,
    Commands\MigrateRollbackCommand::class,
    Commands\MigrateStatusCommand::class,
    Commands\MigrationMakeCommand::class,
    Commands\ModelMakeCommand::class,
    Commands\PublishCommand::class,
    Commands\PublishConfigurationCommand::class,
    Commands\PublishMigrationCommand::class,
    Commands\PublishTranslationCommand::class,
    Commands\SeedCommand::class,
    Commands\SeedMakeCommand::class,
    Commands\SetupCommand::class,
    Commands\UnUseCommand::class,
    Commands\UpdateCommand::class,
    Commands\UseCommand::class,
    Commands\ResourceMakeCommand::class,
    Commands\TestMakeCommand::class,
    Commands\LaravelModulesV6Migrator::class,
],
Outgoings answered 17/2, 2022 at 1:36 Comment(5)
Please share more details. Nwidart does not sound like a namespace that all applications should haveBesmirch
change modules.php in your config folderOutgoings
Please add all clarification to your answer by editing it. What exactly should be changed?Besmirch
change your commands property in modules.php config fileOutgoings
Please add all clarification to your answer by editing itBesmirch
L
8

Just add this line:

use Nwidart\Modules\Commands\CommandMakeCommand;

in first of config/modules.php file as a namespace

Above namespace will resolve only commandMakeCommand issue, but if you want to set all command namespace then you need to add the namespace at the top.

namespace Nwidart\Modules\Commands;
Lewellen answered 7/3, 2022 at 12:12 Comment(0)
C
4

Hope this helps (backup your project first):

  1. First remove nwidart/laravel-modules by running: composer remove nwidart/laravel-modules

  2. Then remove config/modules.php by deleting it.

  3. Reinstall nwidart/laravel-modules by running: composer require nwidart/laravel-modules

Source: Githubhot, the answer by mohamedsharaf

Creodont answered 7/3, 2022 at 17:51 Comment(0)
S
3

If someone is still looking for the answer so follow these steps

As mentioned in this link see here: https://docs.laravelmodules.com/v9/introduction

If you have an existing config file, and you get an error:

Target class [CommandMakeCommand] does not exist

Then the config file will need updating first import the commands class, and in your config folder update the modules.php file includes

use Nwidart\Modules\Commands;

Then replace the commands array with: add Commands\ before each value or simple copy and replace the array

 'commands' => [
    Commands\CommandMakeCommand::class,
    Commands\ComponentClassMakeCommand::class,
    Commands\ComponentViewMakeCommand::class,
    Commands\ControllerMakeCommand::class,
    Commands\DisableCommand::class,
    Commands\DumpCommand::class,
    Commands\EnableCommand::class,
    Commands\EventMakeCommand::class,
    Commands\JobMakeCommand::class,
    Commands\ListenerMakeCommand::class,
    Commands\MailMakeCommand::class,
    Commands\MiddlewareMakeCommand::class,
    Commands\NotificationMakeCommand::class,
    Commands\ProviderMakeCommand::class,
    Commands\RouteProviderMakeCommand::class,
    Commands\InstallCommand::class,
    Commands\ListCommand::class,
    Commands\ModuleDeleteCommand::class,
    Commands\ModuleMakeCommand::class,
    Commands\FactoryMakeCommand::class,
    Commands\PolicyMakeCommand::class,
    Commands\RequestMakeCommand::class,
    Commands\RuleMakeCommand::class,
    Commands\MigrateCommand::class,
    Commands\MigrateRefreshCommand::class,
    Commands\MigrateResetCommand::class,
    Commands\MigrateRollbackCommand::class,
    Commands\MigrateStatusCommand::class,
    Commands\MigrationMakeCommand::class,
    Commands\ModelMakeCommand::class,
    Commands\PublishCommand::class,
    Commands\PublishConfigurationCommand::class,
    Commands\PublishMigrationCommand::class,
    Commands\PublishTranslationCommand::class,
    Commands\SeedCommand::class,
    Commands\SeedMakeCommand::class,
    Commands\SetupCommand::class,
    Commands\UnUseCommand::class,
    Commands\UpdateCommand::class,
    Commands\UseCommand::class,
    Commands\ResourceMakeCommand::class,
    Commands\TestMakeCommand::class,
    Commands\LaravelModulesV6Migrator::class,
],
Sesterce answered 11/6, 2022 at 16:20 Comment(0)
A
2

You can try to downgrade nwidart/laravel-modules version in composer.json file. Just change this line to the below line.

"nwidart/laravel-modules": "8.2.*"

Then delete composer.lock file and now, run this command.

composer install
Antibiosis answered 5/7, 2022 at 8:7 Comment(0)
E
0

in config/modules add name full path to command Nwidart\Modules\Commands

'commands' => [
    Nwidart\Modules\Commands\CommandMakeCommand::class
    ...
],
Endamoeba answered 26/2, 2023 at 9:31 Comment(0)
S
0

Found the solution.

Once you have written your seeder, you may need to regenerate Composer's autoloader using the dump-autoload command:

composer dump-autoload

Sudoriferous answered 23/7, 2024 at 8:49 Comment(0)
L
-1

This Is Not Related Routes Or Any Other Parts Of Your App , When You Cant Run Composer Update Or Artisan Commands You Have Problem In Booting Laravel , In This Case : Go To Your Config Folder Open Modules File And Check "Command" Key My Problem Fixed By This Way ! Good Day !

Lettered answered 16/2, 2022 at 11:48 Comment(3)
Please share more details. How does checking any "command key" resolve the problem?Besmirch
This Error Happened Because Commands That Located In Config/App/modules Can Not Resolved By Laravel So If You Recognised Them For Laravel The Problem Has Will Be Solved ! I Check It Just Today And It Fixed !Lettered
Please add all clarification to your answer by editing it. If Laravel cannot resolve commands in Config/App/modules, how does checking any "Command Key" resolve this?Besmirch
B
-2

use complete path of the Target class

eg :

use App\Models\Company;

or

Route::resource('companies', App\Http\Controllers\CompanyController::class);
Burnet answered 13/6, 2023 at 1:20 Comment(1)
Please add some explanation to your answer such that others can learn from it. The question itself doesn't mention App\Models\Company or any controllerBesmirch

© 2022 - 2025 — McMap. All rights reserved.