16

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
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? Commented Feb 12, 2022 at 16:55

10 Answers 10

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

Sign up to request clarification or add additional context in comments.

4 Comments

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 ?
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",
Downgrading to 8.2 worked for me as well.
Yes, replaced ^8.2 to 8.2 in composer.json file and ran composer update. Fixed the issue, thanks @Farhad!
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,
],

5 Comments

Please share more details. Nwidart does not sound like a namespace that all applications should have
change modules.php in your config folder
Please add all clarification to your answer by editing it. What exactly should be changed?
change your commands property in modules.php config file
Please add all clarification to your answer by editing it
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;

Comments

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

Comments

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,
],

Comments

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

Comments

1

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

Comments

0

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

'commands' => [
    Nwidart\Modules\Commands\CommandMakeCommand::class
    ...
],

Comments

-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 !

3 Comments

Please share more details. How does checking any "command key" resolve the problem?
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 !
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?
-2

use complete path of the Target class

eg :

use App\Models\Company;

or

Route::resource('companies', App\Http\Controllers\CompanyController::class);

1 Comment

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 controller

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.