symfony/http-kernel · error · RuntimeException

Composer autoloader not found.

Error message

Composer autoloader not found.

What it means

HttpCacheBrowser/HttpKernelBrowser::getScript() generates a standalone PHP script that executes the kernel in an isolated process, and it embeds the composer autoloader path. If it cannot locate any autoloader file to require, this RuntimeException is thrown because the generated script could not bootstrap.

Solutions

  1. Run composer install so vendor/autoload.php exists at the expected location
  2. Ensure tests run from the project root where vendor/ is present
  3. If the autoloader lives elsewhere, check how the client locates it and configure accordingly or subclass to inject the path

Example fix

// in CI container before running tests
composer install   # ensures vendor/autoload.php exists
vendor/bin/phpunit
Defensive patterns

Strategy: validation

Validate before calling

$autoloaders = array_filter(array_merge([
    __DIR__.'/../vendor/autoload.php',
    __DIR__.'/vendor/autoload.php',
], spl_autoload_functions() ? [] : []), 'file_exists');
if (!$autoloaders) {
    throw new \RuntimeException('vendor/autoload.php not found; run composer install');
}

Try / catch

try {
    $client->getScript($meta);
} catch (\RuntimeException $e) {
    if (str_contains($e->getMessage(), 'autoloader')) {
        exec('composer install');
    }
}

Prevention

When it happens

Trigger: Running getScript()/the isolated-process test client when the script-generator cannot find a composer autoload file (no vendor/autoload.php discoverable, e.g. vendor directory moved, running outside a composer project, or unusual autoload locations).

Common situations: Test suite executed from a different working directory or container image where vendor/ is not in the expected location; projects using non-composer autoloading; broken vendor directory after a failed install.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/372b81658bc72f1f. Report an issue: GitHub.

Appendix: source

Thrown at HttpKernelBrowser.php:111

    {
        $kernel = var_export(serialize($this->kernel), true);
        $request = var_export(serialize($request), true);

        $errorReporting = error_reporting();

        $requires = '';
        foreach (get_declared_classes() as $class) {
            if (str_starts_with($class, 'ComposerAutoloaderInit')) {
                $r = new \ReflectionClass($class);
                $file = \dirname($r->getFileName(), 2).'/autoload.php';
                if (file_exists($file)) {
                    $requires .= 'require_once '.var_export($file, true).";\n";
                }
            }
        }

        if (!$requires) {
            throw new \RuntimeException('Composer autoloader not found.');
        }

        $code = <<<EOF
            <?php

            error_reporting($errorReporting);

            $requires

            \$kernel = unserialize($kernel);
            \$request = unserialize($request);
            EOF;

        return $code.$this->getHandleScript();
    }

    protected function getHandleScript(): string
    {

View on GitHub (pinned to aa3a39d728)