symfony/symfony · error · InvalidArgumentException

"%s" is neither an enabled bundle nor a directory.

Error message

"%s" is neither an enabled bundle nor a directory.

What it means

Thrown by `debug:translation` when the optional `bundle` argument does not resolve to a registered bundle (the kernel's `getBundle()` throws `InvalidArgumentException`) AND the same value treated as a filesystem path has no `translations/` subdirectory. The command tries the bundle registry first, then falls back to treating the argument as a directory path, and only throws when both fail.

Source

Thrown at src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php:149

                $bundle = $kernel->getBundle($input->getArgument('bundle'));
                $bundleDir = $bundle->getPath();
                $transPaths = [is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundleDir.'/translations'];
                $codePaths = [is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundleDir.'/templates'];
                if ($this->defaultTransPath) {
                    $transPaths[] = $this->defaultTransPath;
                }
                if ($this->defaultViewsPath) {
                    $codePaths[] = $this->defaultViewsPath;
                }
            } catch (\InvalidArgumentException) {
                // such a bundle does not exist, so treat the argument as path
                $path = $input->getArgument('bundle');

                $transPaths = [$path.'/translations'];
                $codePaths = [$path.'/templates'];

                if (!is_dir($transPaths[0])) {
                    throw new InvalidArgumentException(\sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
                }
            }
        } elseif ($input->getOption('all')) {
            foreach ($kernel->getBundles() as $bundle) {
                $bundleDir = $bundle->getPath();
                $transPaths[] = is_dir($bundleDir.'/Resources/translations') ? $bundleDir.'/Resources/translations' : $bundle->getPath().'/translations';
                $codePaths[] = is_dir($bundleDir.'/Resources/views') ? $bundleDir.'/Resources/views' : $bundle->getPath().'/templates';
            }
        }

        // Extract used messages
        $extractedCatalogue = $this->extractMessages($locale, $codePaths);

        // Load defined messages
        $currentCatalogue = $this->loadCurrentMessages($locale, $transPaths);

        // Merge defined and extracted messages to get all message ids
        $mergeOperation = new MergeOperation($extractedCatalogue, $currentCatalogue);

View on GitHub (pinned to 698e28026c)

Solutions

  1. Check `config/bundles.php` to confirm the bundle is registered and note its exact name.
  2. If passing a path, ensure it contains a `translations/` subdirectory.
  3. Run without the bundle argument to debug application-level translations in the default directory.
  4. Use `--all` to scan all registered bundles instead of naming one.

Example fix

// before
php bin/console debug:translation en AcmeDemo

// after (correct bundle name or a real path)
php bin/console debug:translation en AcmeDemoBundle
# or
php bin/console debug:translation en /full/path/with/translations
Defensive patterns

Strategy: validation

Validate before calling

// Validate the bundle argument before scripting the command.
$bundles = array_map(fn($b) => $b->getName(), $kernel->getBundles());
$isBundle = in_array($arg, $bundles, true);
$isDir = is_dir($arg.'/translations');
if (!$isBundle && !$isDir) {
    // neither bundle nor directory; reject early
}

Type guard

function bundleOrDirIsValid(\Symfony\Component\HttpKernel\KernelInterface $kernel, string $arg): bool
{
    $names = array_map(fn($b) => $b->getName(), $kernel->getBundles());
    return in_array($arg, $names, true) || is_dir($arg.'/translations');
}

Try / catch

try {
    $exit = $command->run($input, $output);
} catch (\Symfony\Component\Console\Exception\InvalidArgumentException $e) {
    // list bundles or check the directory path
}

Prevention

When it happens

Trigger: Running `php bin/console debug:translation en SomeBundle` where `SomeBundle` is not registered in the kernel, or `debug:translation en /path/to/something` where `/path/to/something/translations/` does not exist.

Common situations: Bundle name typo, bundle not enabled in `config/bundles.php`, bundle registered under a different alias (extension alias vs bundle class name), or pointing at a directory that lacks the expected `translations/` structure.

Related errors


AI-assisted analysis of symfony/symfony@698e28026c (2026-08-06). Data as JSON: /api/errors/d258009b972328f1. Report an issue: GitHub.