symfony/symfony · error · LogicException

Serializer support cannot be enabled as the Serializer compo

Error message

Serializer support cannot be enabled as the Serializer component is not installed. Try running "composer require symfony/serializer-pack".

What it means

Thrown by FrameworkExtension when serializer support is enabled but the symfony/serializer component is not installed. The Serializer class is required; the suggested install is `symfony/serializer-pack` which pulls the component plus normalizer/encoder dependencies.

Source

Thrown at src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php:447

        $exceptionListener = $container->getDefinition('exception_listener');

        $loggers = [];
        foreach ($config['exceptions'] as $exception) {
            if (!isset($exception['log_channel'])) {
                continue;
            }
            $loggers[$exception['log_channel']] = new Reference('monolog.logger.'.$exception['log_channel'], ContainerInterface::NULL_ON_INVALID_REFERENCE);
        }

        $exceptionListener
            ->replaceArgument(3, $config['exceptions'])
            ->setArgument(4, $loggers)
        ;

        if ($this->readConfigEnabled('serializer', $container, $config['serializer'])) {
            if (!class_exists(Serializer::class)) {
                throw new LogicException('Serializer support cannot be enabled as the Serializer component is not installed. Try running "composer require symfony/serializer-pack".');
            }

            $this->registerSerializerConfiguration($config['serializer'], $container, $loader);
        } else {
            $container->getDefinition('argument_resolver.request_payload')
                ->setArguments([])
                ->addError('You can neither use "#[MapRequestPayload]" nor "#[MapQueryString]" since the Serializer component is not '
                    .(class_exists(Serializer::class) ? 'enabled. Try setting "framework.serializer.enabled" to true.' : 'installed. Try running "composer require symfony/serializer-pack".')
                )
                ->addTag('container.error')
                ->clearTag('kernel.event_subscriber');

            $container->removeDefinition('console.command.serializer_debug');
        }

        if ($typeInfoEnabled = $this->readConfigEnabled('type_info', $container, $config['type_info'])) {
            $this->registerTypeInfoConfiguration($config['type_info'], $container, $loader);
        }

View on GitHub (pinned to 698e28026c)

Solutions

  1. Install the pack: `composer require symfony/serializer-pack` (or `composer require symfony/serializer`).
  2. Or disable the serializer: `framework.serializer.enabled: false` and remove usages of serializer-based features.

Example fix

# before
framework:
    serializer:
        enabled: true

# fix option A
#   composer require symfony/serializer-pack

# fix option B
framework:
    serializer:
        enabled: false
Defensive patterns

Strategy: validation

Validate before calling

if (($config['serializer']['enabled'] ?? false) && !class_exists(\Symfony\Component\Serializer\Serializer::class)) {
    throw new \LogicException('Install symfony/serializer-pack before enabling framework.serializer.');
}

Type guard

function serializerIsInstalled(): bool
{
    return class_exists(\Symfony\Component\Serializer\Serializer::class);
}

Prevention

When it happens

Trigger: Setting `framework.serializer.enabled: true` while `symfony/serializer` (and its pack) is absent. Note: this also gates `#[MapRequestPayload]` / `#[MapQueryString]`, which produce a different (added-error) message when serializer is disabled rather than absent.

Common situations: Enabling the serializer for API endpoints on a project that pruned the dependency; a new app skeleton that didn't include the serializer pack.

Related errors


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