symfony/routing · error · LogicException

Unable to use expressions as the Symfony ExpressionLanguage…

Error message

Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".

What it means

CompiledUrlMatcherDumper::getExpressionLanguage() compiles route conditions written as expressions (condition: "request... "). It throws this LogicException when the symfony/expression-language package is not installed. The compiled matcher requires the component at dump time, not just at runtime.

Solutions

  1. Run composer require symfony/expression-language
  2. Remove the condition: from the route if the expression is not actually needed
  3. Move the gating logic into the controller or a kernel listener instead of a route expression

Example fix

// shell
composer require symfony/expression-language
Defensive patterns

Strategy: fallback

Validate before calling

if (str_contains($routeContent, 'condition:') && !class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class)) { /* install component or drop conditions */ }

Type guard

function expressionLanguageAvailable(): bool { return class_exists(\Symfony\Component\ExpressionLanguage\ExpressionLanguage::class); }

Try / catch

try { $routes = $dumper->dump(); } catch (\LogicException $e) { if (str_contains($e->getMessage(), 'ExpressionLanguage component is not installed')) { /* suggest composer require */ } throw $e; }

Prevention

When it happens

Trigger: Any route has a condition: key using an expression (e.g. "context.getMethod() in ['POST']") while compiling/optimizing routes for a CompiledUrlMatcher and symfony/expression-language is absent from vendor/.

Common situations: Deploying without composer require symfony/expression-language after adding a condition to a route; production builds pruning dev dependencies that pulled the component transitively.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14). Data as JSON: /api/errors/693493379ad4bd2e. Report an issue: GitHub.

Appendix: source

Thrown at Matcher/Dumper/CompiledUrlMatcherDumper.php:452

            $condition = null;
        }

        return [
            ['_route' => $name] + $defaults,
            $vars,
            array_flip($route->getMethods()) ?: null,
            array_flip($route->getSchemes()) ?: null,
            $hasTrailingSlash,
            $hasTrailingVar,
            $condition,
        ];
    }

    private function getExpressionLanguage(): ExpressionLanguage
    {
        if (!isset($this->expressionLanguage)) {
            if (!class_exists(ExpressionLanguage::class)) {
                throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed. Try running "composer require symfony/expression-language".');
            }
            $this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);
        }

        return $this->expressionLanguage;
    }

    private function indent(string $code, int $level = 1): string
    {
        return preg_replace('/^./m', str_repeat('    ', $level).'$0', $code);
    }

    /**
     * @internal
     */
    public static function export(mixed $value): string
    {
        if (null === $value) {

View on GitHub (pinned to 83fa223250)