symfony/symfony · error · Twig\Error\SyntaxError

Did you forget to run "composer require %s"? Unknown %s "%s"

Error message

Did you forget to run "composer require %s"? Unknown %s "%s".

What it means

Thrown by Twig's undefined-callable handler when an undefined Twig filter that Symfony recognizes as belonging to a known component is invoked. The handler maps filters like 'trans', 'serialize', 'emojify', 'humanize', 'normalize', 'sanitize_html', 'yaml_encode/dump', 'form_encode_currency' to their providing package and tells you which composer package to install (or, in full-stack, which config to enable).

Source

Thrown at src/Symfony/Bridge/Twig/UndefinedCallableHandler.php:101

        'workflow_transition_blockers' => 'workflow',
    ];

    private const FULL_STACK_ENABLE = [
        'html-sanitizer' => 'enable "framework.html_sanitizer"',
        'form' => 'enable "framework.form"',
        'security-core' => 'add the "SecurityBundle"',
        'security-http' => 'add the "SecurityBundle"',
        'web-link' => 'enable "framework.web_link"',
        'workflow' => 'enable "framework.workflows"',
    ];

    public static function onUndefinedFilter(string $name): TwigFilter|false
    {
        if (!isset(self::FILTER_COMPONENTS[$name])) {
            return false;
        }

        throw new SyntaxError(self::onUndefined($name, 'filter', self::FILTER_COMPONENTS[$name]));
    }

    public static function onUndefinedFunction(string $name): TwigFunction|false
    {
        if (!isset(self::FUNCTION_COMPONENTS[$name])) {
            return false;
        }

        if ('webpack-encore-bundle' === self::FUNCTION_COMPONENTS[$name]) {
            return new TwigFunction($name, static fn () => '');
        }

        throw new SyntaxError(self::onUndefined($name, 'function', self::FUNCTION_COMPONENTS[$name]));
    }

    private static function onUndefined(string $name, string $type, string $component): string
    {
        if (class_exists(FullStack::class) && isset(self::FULL_STACK_ENABLE[$component])) {

View on GitHub (pinned to 698e28026c)

Solutions

  1. Run the suggested composer require command, e.g. composer require symfony/translation for the 'trans' filter.
  2. If the package is already installed (InstalledVersions::isInstalled returns true), the handler points to symfony/twig-bundle — install/register twig-bundle so the extension is loaded.
  3. For full-stack Symfony, enable the relevant framework config (e.g. framework.html_sanitizer) instead of installing a package.

Example fix

# before: filter 'trans' is undefined
composer require symfony/translation
# then clear cache: php bin/console cache:clear
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the component is installed before relying on a filter
use Composer\InstalledVersions;
if (!InstalledVersions::isInstalled('symfony/translation')) {
    throw new \LogicException('Install symfony/translation to use the trans filter.');
}

Try / catch

try {
    $twig->render($template, $vars);
} catch (\Twig\Error\SyntaxError $e) {
    if (str_contains($e->getMessage(), 'composer require')) {
        // parse suggested package, install it, clear cache, retry
    }
    throw $e;
}

Prevention

When it happens

Trigger: Using a Twig filter (e.g. {{ x|trans }}, {{ data|serialize }}, {{ md|sanitize_html }}) in a template while the corresponding Symfony component (symfony/translation, symfony/serializer, symfony/html-sanitizer) is not installed, or the Twig bridge extension is not registered.

Common situations: Starting a new project and using translation/serializer/emoji filters without requiring the package. Removing a dependency but leaving template filters referencing it. The package is installed but the bridge extension isn't wired into the Twig environment.

Related errors


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