【问题标题】:Illuminate\Contracts\Container\BindingResolutionException - Target class [CommandMakeCommand] does not existIlluminate\Contracts\Container\BindingResolutionException - 目标类 [CommandMakeCommand] 不存在
【发布时间】:2022-04-20 19:08:18
【问题描述】:

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

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

【问题讨论】:

  • 您尝试过什么来解决问题?你被困在哪里了?请记住,Laravel 8.75 不是最新版本,所以更新可能已经有所帮助?

标签: php laravel composer-php


【解决方案1】:

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

【讨论】:

  • 自过去 2 天以来,我在 laravel 8 上的少数应用程序上也遇到了同样的问题,但仍未解决。我也有 nwidart/laravel-modules 包,它是 8.2 并且没有升级,我使用的是 laravel 8.40。有人知道吗?
  • 删除 composer.lock 和供应商文件夹(可能是在 composer.lock 文件中升级了 laravel-modules),并在 composer.json 中将 laravel-modules 修复为 8.2,“nwidart/laravel-modules”:“8.2 ",
  • 降级到 8.2 也对我有用。
【解决方案2】:

请看这里:https://docs.laravelmodules.com/v9/introduction

如果你有一个现有的配置文件,你得到一个错误:

Target class [CommandMakeCommand] does not exist

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

use Nwidart\Modules\Commands;

接下来将 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,
],

【讨论】:

  • 请分享更多细节。 Nwidart 听起来不像是所有应用程序都应该拥有的命名空间
  • 更改配置文件夹中的 modules.php
  • 请通过编辑添加all 澄清到您的答案。究竟应该改变什么?
  • 在 modules.php 配置文件中更改 commands 属性
  • 请通过编辑将所有说明添加到您的答案中
【解决方案3】:

希望这会有所帮助(先备份您的项目):

  1. 首先通过运行删除 nwidart/laravel-modules:composer remove nwidart/laravel-modules

  2. 然后删除config/modules.php

  3. 运行以下命令重新安装 nwidart/laravel-modules:composer require nwidart/laravel-modules

来源: Githubhot, the answer by mohamedsharaf

【讨论】:

  • 完美运行
【解决方案4】:

只需添加这一行:

use Nwidart\Modules\Commands\CommandMakeCommand;

config/modules.php 文件的第一个namespace

【讨论】:

    【解决方案5】:

    如果之前的回复对您不起作用, 如果在composer.json中更改版本以及删除composer.lock和供应商后仍然无法使用,您可以这样修复版本

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

    删除 composer.lock 和 vendor 并运行

    composer install
    

    【讨论】:

    • 删除 composer.lock 对更新的包来说不是必需的,因为这会重新计算 所有 依赖项。通常,这不是你想要的
    【解决方案6】:

    这与您的应用程序的相关路线或任何其他部分无关, 当您无法运行 Composer 更新或 Artisan 命令时 您在启动 Laravel 时遇到问题,在这种情况下: 转到您的配置文件夹打开模块文件并检查“命令”键 我的问题通过这种方式解决了! 美好的一天!

    【讨论】:

    • 请分享更多细节。检查任何“命令键”如何解决问题?
    • 发生此错误是因为 Laravel 无法解析位于 Config/App/modules 中的命令,所以如果您为 Laravel 识别它们,问题将得到解决!我今天才检查它并修复了!
    • 请通过编辑为您的答案添加所有说明。如果 Laravel 无法解析 Config/App/modules 中的命令,检查任何“命令键”如何解决这个问题?
    猜你喜欢
    • 1970-01-01
    • 2021-08-17
    • 2021-09-02
    • 2021-06-24
    • 2021-09-15
    • 1970-01-01
    • 2021-09-04
    • 2021-05-12
    • 1970-01-01
    相关资源
    最近更新 更多