symfony/http-kernel · error · LogicException
You cannot use " " as the HttpClient component is not…
Error message
You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".
What it means
HttpClientKernel lets the test client route requests through symfony/http-client instead of a real HTTP kernel. Constructing it without providing an HttpClientInterface while the symfony/http-client component is not installed throws this LogicException at __construct time.
Solutions
- Run composer require symfony/http-client
- Or explicitly pass an HttpClientInterface instance to the constructor
- Or remove/avoid HttpClientKernel and use KernelBrowser directly
Example fix
// before $kernel = new HttpClientKernel($httpKernel); // after composer require symfony/http-client $kernel = new HttpClientKernel($httpKernel); // or: new HttpClientKernel($httpKernel, $myClient)
Defensive patterns
Strategy: validation
Validate before calling
if (!class_exists(\Symfony\Component\HttpClient\HttpClient::class)) {
throw new \LogicException('symfony/http-client required for HttpClientKernel; run composer require symfony/http-client');
}
$kernel = new HttpClientKernel($httpKernel); Try / catch
try {
$client = new HttpClientKernel($httpKernel);
} catch (\LogicException $e) {
// fall back to the plain kernel browser
$client = new KernelBrowser($httpKernel);
} Prevention
- Require symfony/http-client in composer.json if you use HttpClientKernel
- Verify optional packages exist in CI
- Read the LogicException message — it names the exact composer command
When it happens
Trigger: new HttpClientKernel() (or DI auto-wiring it) with no client argument in a project where symfony/http-client is absent.
Common situations: Using the test framework's HTTP client abstraction without composer require symfony/http-client; moving code to a production build without dev requirements.
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 pass non-empty bodies as the Mime component is…
- Cannot evaluate Expression for controllers since no…
- The "symfony/serializer" component is required to use the "#
- Request payload contains invalid "form" data.
- Unsupported format: " ".
AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13).
Data as JSON: /api/errors/511766adc6090ed6.
Report an issue: GitHub.
Appendix: source
Thrown at HttpClientKernel.php:39
use Symfony\Component\Mime\Part\TextPart;
use Symfony\Contracts\HttpClient\HttpClientInterface;
// Help opcache.preload discover always-needed symbols
class_exists(ResponseHeaderBag::class);
/**
* An implementation of a Symfony HTTP kernel using a "real" HTTP client.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class HttpClientKernel implements HttpKernelInterface
{
private HttpClientInterface $client;
public function __construct(?HttpClientInterface $client = null)
{
if (null === $client && !class_exists(HttpClient::class)) {
throw new \LogicException(\sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__));
}
$this->client = $client ?? HttpClient::create();
}
public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true): Response
{
$headers = $this->getHeaders($request);
$body = '';
if (null !== $part = $this->getBody($request)) {
$headers = array_merge($headers, $part->getPreparedHeaders()->toArray());
$body = $part->bodyToIterable();
}
$response = $this->client->request($request->getMethod(), $request->getUri(), [
'headers' => $headers,
'body' => $body,
] + $request->attributes->get('http_client_options', []));
View on GitHub (pinned to aa3a39d728)