{"record":{"id":"813b46d6dc231e95","repo":"rectorphp/rector","slug":"bootstrap-file-s-does-not-exist","errorCode":null,"errorMessage":"Bootstrap file \"%s\" does not exist.","messagePattern":"Bootstrap file \"(.+?)\" does not exist\\.","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"src/Autoloading/BootstrapFilesIncluder.php","lineNumber":30,"sourceCode":"use SplFileInfo;\nuse RectorPrefix202608\\Webmozart\\Assert\\Assert;\n/**\n * @see \\Rector\\Tests\\Autoloading\\BootstrapFilesIncluderTest\n */\nfinal class BootstrapFilesIncluder\n{\n    /**\n     * Inspired by\n     * @see https://github.com/phpstan/phpstan-src/commit/aad1bf888ab7b5808898ee5fe2228bb8bb4e4cf1\n     */\n    public function includeBootstrapFiles(Container $container): void\n    {\n        $bootstrapFiles = SimpleParameterProvider::provideArrayParameter(Option::BOOTSTRAP_FILES);\n        Assert::allString($bootstrapFiles);\n        /** @var string[] $bootstrapFiles */\n        foreach ($bootstrapFiles as $bootstrapFile) {\n            if (!is_file($bootstrapFile)) {\n                throw new ShouldNotHappenException(sprintf('Bootstrap file \"%s\" does not exist.', $bootstrapFile));\n            }\n            // mimic PHPStan bootstrap file inclusion (bootstrap files have access to the global $container variable)\n            (static function (string $file) use ($container): void {\n                require $file;\n            })($bootstrapFile);\n        }\n        $this->requireRectorStubs();\n    }\n    private function requireRectorStubs(): void\n    {\n        $stubsRectorDirectory = realpath(__DIR__ . '/../../stubs-rector');\n        if ($stubsRectorDirectory === \\false) {\n            return;\n        }\n        $dir = new RecursiveDirectoryIterator($stubsRectorDirectory, RecursiveDirectoryIterator::SKIP_DOTS);\n        $stubs = new RecursiveIteratorIterator($dir);\n        foreach ($stubs as $stub) {\n            /** @var SplFileInfo $stub */","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Autoloading/BootstrapFilesIncluder.php#L12-L48","documentation":"BootstrapFilesIncluder loads every file listed in the BOOTSTRAP_FILES parameter (set by ->withBootstrapFiles([...]) in rector.php or --bootstrap-file on the CLI) before analysis starts, so user code needed by custom rules is loaded. Each path is checked with is_file() and a missing one aborts immediately with ShouldNotHappenException. Relative paths are resolved against the current working directory, which is the usual culprit.","triggerScenarios":"Calling ->withBootstrapFiles(['bootstrap/rector-bootstrap.php']) or --bootstrap-file=boot.php where the path is relative and rector runs from a different cwd (e.g. from a subdirectory, via a global binary, or in CI with a different working directory), or the file was simply deleted/renamed.","commonSituations":"Monorepo where rector runs at the repo root but rector.php lives in a package and uses relative paths; CI checking out the config without the bootstrap file; typos in the path.","solutions":["Use absolute paths anchored on the config file: ->withBootstrapFiles([__DIR__ . '/rector-bootstrap.php'])","Verify the file exists: ls the exact path from the directory where you run rector","If you run rector from another directory, cd to the project root or fix the relative path accordingly"],"exampleFix":"// before: relative path breaks when cwd differs\nreturn RectorConfig::configure()\n    ->withBootstrapFiles(['bootstrap/rector-bootstrap.php']);\n\n// after: absolute path relative to the config file\nreturn RectorConfig::configure()\n    ->withBootstrapFiles([__DIR__ . '/bootstrap/rector-bootstrap.php']);","handlingStrategy":"validation","validationCode":"// in rector.php, before registering\n$bootstrapFile = __DIR__ . '/bootstrap/rector-bootstrap.php';\nif (! is_file($bootstrapFile)) {\n    throw new InvalidArgumentException('Bootstrap file missing: ' . $bootstrapFile);\n}\nreturn RectorConfig::configure()->withBootstrapFiles([$bootstrapFile]);","typeGuard":"function isExistingBootstrapFile(string $path): bool\n{\n    return is_file($path) && is_readable($path);\n}","tryCatchPattern":null,"preventionTips":["Always build bootstrap paths with __DIR__ so they are cwd-independent","Add bootstrap files to the same VCS/checkout as rector.php so CI always has them","Use --bootstrap-file only with absolute paths in scripts"],"tags":["php","rector","bootstrap","config","file-not-found"],"backgroundTag":"missing-bootstrap-file","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}