laravel/framework · error · CommandNotFoundException

Command "%s" does not exist.

Error message

Command "%s" does not exist.

What it means

Thrown by ContainerCommandLoader::get() (src/Illuminate/Console/ContainerCommandLoader.php:49) when Symfony's console asks for a command name not present in the command map. The loader is a lazy registry; has() checks isset($this->commandMap[$name]).

Source

Thrown at src/Illuminate/Console/ContainerCommandLoader.php:49

     */
    public function __construct(ContainerInterface $container, array $commandMap)
    {
        $this->container = $container;
        $this->commandMap = $commandMap;
    }

    /**
     * Resolve a command from the container.
     *
     * @param  string  $name
     * @return \Symfony\Component\Console\Command\Command
     *
     * @throws \Symfony\Component\Console\Exception\CommandNotFoundException
     */
    public function get(string $name): Command
    {
        if (! $this->has($name)) {
            throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
        }

        return $this->container->get($this->commandMap[$name]);
    }

    /**
     * Determines if a command exists.
     *
     * @param  string  $name
     * @return bool
     */
    public function has(string $name): bool
    {
        return $name && isset($this->commandMap[$name]);
    }

    /**
     * Get the command names.

View on GitHub (pinned to bd6b5437e6)

Solutions

  1. Add the command name => class binding to the commandMap array passed to ContainerCommandLoader.
  2. Use the Application::add() convenience instead of lazy loading for simple cases.
  3. Verify command name with $loader->has($name) before calling $loader->get($name).
  4. Ensure the command's getName() matches the key in the map.

Example fix

// before
$loader = new ContainerCommandLoader($container, [
    'migrate' => MigrateCommand::class,
]);
$loader->get('migrate:fresh');  // missing

// after
$loader = new ContainerCommandLoader($container, [
    'migrate' => MigrateCommand::class,
    'migrate:fresh' => MigrateFreshCommand::class,
]);
Defensive patterns

Strategy: validation

Validate before calling

if (! $loader->has($name)) {
    // command missing from commandMap; add it before calling get()
}

Type guard

// has() is itself the guard
$exists = $loader->has($name);

Try / catch

use Symfony\Component\Console\Exception\CommandNotFoundException;
try {
    $cmd = $loader->get($name);
} catch (CommandNotFoundException $e) {
    // fall back to a default command or error
}

Prevention

When it happens

Trigger: Symfony Console resolves a command lazily via the loader (typically via Application::find/get) and the name is absent from the commandMap passed to the loader at construction time.

Common situations: Building a standalone Symfony Console app wired with Illuminate's ContainerCommandLoader and forgetting to add the command to the map, or referencing an alias not present in the map.

Related errors


AI-assisted analysis of laravel/framework@bd6b5437e6 (2026-08-06). Data as JSON: /data/errors/6ea771bdd6593cc8.json. Report an issue: GitHub.