symfony/translation · error · LogicException
You cannot use " " as the "symfony/finder" package is not…
Error message
You cannot use "%s" as the "symfony/finder" package is not installed. Try running "composer require symfony/finder".
What it means
PhpAstExtractor::extractFromDirectory() uses symfony/finder's Finder to iterate PHP files in the given directories. If the Finder class does not exist (package not installed), it throws LogicException with the composer require hint.
Solutions
- Run: composer require symfony/finder
- Ensure the package is in the require (not suggest/dev) section if you extract from directories
- Extract from individual file resources instead of directories (if feasible)
Example fix
// before (shell) php bin/console translation:extract en --dir=src // after (shell) composer require symfony/finder php bin/console translation:extract en --dir=src
Defensive patterns
Strategy: fallback
Validate before calling
if (!class_exists(\Symfony\Component\Finder\Finder::class)) {
// skip directory extraction or require the package
} Type guard
function hasFinder(): bool {
return class_exists(\Symfony\Component\Finder\Finder::class);
} Try / catch
try {
$extractor->extract('src/', $catalogue);
} catch (\LogicException $e) {
throw new \RuntimeException('Run: composer require symfony/finder', 0, $e);
} Prevention
- Require symfony/finder in composer.json when extracting from directories
- Avoid --no-dev installs in translation-extraction pipelines
- Pin the framework's suggested packages in a requirements check
When it happens
Trigger: Calling extract() with a directory resource on an install lacking symfony/finder; the finder package was made optional and your install skipped it.
Common situations: Translation extraction over directories in a slimmed-down deployment; version upgrade where symfony/finder moved from required to suggested; custom tooling instantiating PhpAstExtractor directly.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- You cannot use " " as the "nikic/php-parser" package is not…
- Loading translations from the Xliff format requires the…
- Loading translations from the YAML format requires the…
- Dumping translations in the YAML format requires the…
- Cannot parse message translation: please install the "intl"…
AI-assisted analysis of symfony/translation@ae9e8a51bc (2026-09-15).
Data as JSON: /api/errors/fe1ece2e3e5aea27.
Report an issue: GitHub.
Appendix: source
Thrown at Extractor/PhpAstExtractor.php:79
}
}
public function setPrefix(string $prefix): void
{
$this->prefix = $prefix;
}
protected function canBeExtracted(string $file): bool
{
return 'php' === pathinfo($file, \PATHINFO_EXTENSION)
&& $this->isFile($file)
&& preg_match('/\bt\(|->trans\(|TranslatableMessage|Symfony\\\\Component\\\\Validator\\\\Constraints/i', file_get_contents($file));
}
protected function extractFromDirectory(array|string $resource): iterable|Finder
{
if (!class_exists(Finder::class)) {
throw new \LogicException(\sprintf('You cannot use "%s" as the "symfony/finder" package is not installed. Try running "composer require symfony/finder".', static::class));
}
return (new Finder())->files()->name('*.php')->in($resource);
}
}
View on GitHub (pinned to ae9e8a51bc)