{"record":{"id":"511766adc6090ed6","repo":"symfony/http-kernel","slug":"you-cannot-use-s-as-the-httpclient-component-is-not","errorCode":null,"errorMessage":"You cannot use \"%s\" as the HttpClient component is not installed. Try running \"composer require symfony/http-client\".","messagePattern":"You cannot use \"(.+?)\" as the HttpClient component is not installed\\. Try running \"composer require symfony/http-client\"\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"HttpClientKernel.php","lineNumber":39,"sourceCode":"use Symfony\\Component\\Mime\\Part\\TextPart;\nuse Symfony\\Contracts\\HttpClient\\HttpClientInterface;\n\n// Help opcache.preload discover always-needed symbols\nclass_exists(ResponseHeaderBag::class);\n\n/**\n * An implementation of a Symfony HTTP kernel using a \"real\" HTTP client.\n *\n * @author Fabien Potencier <fabien@symfony.com>\n */\nfinal class HttpClientKernel implements HttpKernelInterface\n{\n    private HttpClientInterface $client;\n\n    public function __construct(?HttpClientInterface $client = null)\n    {\n        if (null === $client && !class_exists(HttpClient::class)) {\n            throw new \\LogicException(\\sprintf('You cannot use \"%s\" as the HttpClient component is not installed. Try running \"composer require symfony/http-client\".', __CLASS__));\n        }\n\n        $this->client = $client ?? HttpClient::create();\n    }\n\n    public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true): Response\n    {\n        $headers = $this->getHeaders($request);\n        $body = '';\n        if (null !== $part = $this->getBody($request)) {\n            $headers = array_merge($headers, $part->getPreparedHeaders()->toArray());\n            $body = $part->bodyToIterable();\n        }\n        $response = $this->client->request($request->getMethod(), $request->getUri(), [\n            'headers' => $headers,\n            'body' => $body,\n        ] + $request->attributes->get('http_client_options', []));\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/HttpClientKernel.php#L21-L57","documentation":"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.","triggerScenarios":"new HttpClientKernel() (or DI auto-wiring it) with no client argument in a project where symfony/http-client is absent.","commonSituations":"Using the test framework's HTTP client abstraction without composer require symfony/http-client; moving code to a production build without dev requirements.","solutions":["Run composer require symfony/http-client","Or explicitly pass an HttpClientInterface instance to the constructor","Or remove/avoid HttpClientKernel and use KernelBrowser directly"],"exampleFix":"// before\n$kernel = new HttpClientKernel($httpKernel);\n// after\ncomposer require symfony/http-client\n$kernel = new HttpClientKernel($httpKernel); // or: new HttpClientKernel($httpKernel, $myClient)","handlingStrategy":"validation","validationCode":"if (!class_exists(\\Symfony\\Component\\HttpClient\\HttpClient::class)) {\n    throw new \\LogicException('symfony/http-client required for HttpClientKernel; run composer require symfony/http-client');\n}\n$kernel = new HttpClientKernel($httpKernel);","typeGuard":null,"tryCatchPattern":"try {\n    $client = new HttpClientKernel($httpKernel);\n} catch (\\LogicException $e) {\n    // fall back to the plain kernel browser\n    $client = new KernelBrowser($httpKernel);\n}","preventionTips":["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"],"tags":["http-client","missing-dependency","symfony"],"backgroundTag":"missing-dependency","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}