Illuminate\Contracts\Container\BindingResolutionException - 目标类 [CommandMakeCommand] 不存在

imt*_*ode 11 php laravel composer-php

使用Laravel 8.75并尝试将composer.json中的php 8.1升级为“php”:“^8.1”并收到错误 Illuminate\\Contracts\\Container\\BindingResolutionException - 目标类 [CommandMakeCommand] 不存在。

\n
Loading composer repositories with package information\nUpdating dependencies\nNothing to modify in lock file\nInstalling dependencies from lock file (including require-dev)\nNothing to install, update or remove\nPackage swiftmailer/swiftmailer is abandoned, you should avoid using it. \nUse symfony/mailer instead.\nGenerating optimized autoload files\n \nIlluminate\\Foundation\\ComposerScripts::postAutoloadDump\n@php artisan package:discover --ansi\n\nIlluminate\\Contracts\\Container\\BindingResolutionException\n\nTarget class [CommandMakeCommand] does not exist.\n\nat \n
Run Code Online (Sandbox Code Playgroud)\n

供应商/laravel/framework/src/Illuminate/Container/Container.php:879

\n
875\xe2\x96\x95\n876\xe2\x96\x95         try {\n877\xe2\x96\x95             $reflector = new ReflectionClass($concrete);\n878\xe2\x96\x95         } catch (ReflectionException $e) {\n879\xe2\x96\x95             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);\n880\xe2\x96\x95         }\n881\xe2\x96\x95\n882\xe2\x96\x95         // If the type is not instantiable, the developer is attempting to resolve\n883\xe2\x96\x95         // an abstract type such as an Interface or Abstract Class and there is\n\n  +13 vendor frames\n 14  artisan:37\n Illuminate\\Foundation\\Console\\Kernel::handle()\nScript @php artisan package:discover --ansi handling the post-autoload- \ndump event returned with error code 1\n
Run Code Online (Sandbox Code Playgroud)\n

Far*_*had 19

我也有同样的问题,在我的例子中,nwidart/laravel-modules 包升级到 8.3 版本,我降级到 8.2 版本,问题解决了

  • 删除composer.lock和vendor文件夹(也许laravel-modules在composer.lock文件中升级),并在composer.json中将laravel-modules修复为8.2,“nwidart/laravel-modules”:“8.2”, (5认同)

Lim*_*eat 9

请参阅此处: https: //docs.laravelmodules.com/v9/introduction

如果您有现有的配置文件,并且会收到错误消息:

Target class [CommandMakeCommand] does not exist

然后配置文件需要首先更新导入命令类:

use Nwidart\Modules\Commands;

接下来将命令数组替换为:

'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,
],
Run Code Online (Sandbox Code Playgroud)


Dol*_*rma 7

只需添加这一行:

use Nwidart\Modules\Commands\CommandMakeCommand;
Run Code Online (Sandbox Code Playgroud)

在文件的第config/modules.php一个中作为namespace

上面的命名空间只会解决 commandMakeCommand 问题,但如果你想设置所有命令命名空间,那么你需要在顶部添加命名空间。

namespace Nwidart\Modules\Commands;
Run Code Online (Sandbox Code Playgroud)