{"record":{"id":"6bbfb077b248e17f","repo":"twigphp/Twig","slug":"the-s-directory-does-not-exist-s","errorCode":null,"errorMessage":"The \"%s\" directory does not exist (\"%s\").","messagePattern":"The \"(.+?)\" directory does not exist \\(\"(.+?)\"\\)\\.","errorType":"exception","errorClass":"LoaderError","httpStatus":null,"severity":"error","filePath":"src/Loader/FilesystemLoader.php","lineNumber":99,"sourceCode":"        }\n\n        $this->paths[$namespace] = [];\n        foreach ($paths as $path) {\n            $this->addPath($path, $namespace);\n        }\n    }\n\n    /**\n     * @throws LoaderError\n     */\n    public function addPath(string $path, string $namespace = self::MAIN_NAMESPACE): void\n    {\n        // invalidate the cache\n        $this->cache = $this->errorCache = [];\n\n        $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;\n        if (!is_dir($checkPath)) {\n            throw new LoaderError(\\sprintf('The \"%s\" directory does not exist (\"%s\").', $path, $checkPath));\n        }\n\n        $this->paths[$namespace][] = rtrim($path, '/\\\\');\n    }\n\n    /**\n     * @throws LoaderError\n     */\n    public function prependPath(string $path, string $namespace = self::MAIN_NAMESPACE): void\n    {\n        // invalidate the cache\n        $this->cache = $this->errorCache = [];\n\n        $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path;\n        if (!is_dir($checkPath)) {\n            throw new LoaderError(\\sprintf('The \"%s\" directory does not exist (\"%s\").', $path, $checkPath));\n        }\n","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/twigphp/Twig/blob/a414c3a491defb5a60f2fc88ef79ff37c90010cd/src/Loader/FilesystemLoader.php#L81-L117","documentation":"FilesystemLoader::addPath() validates that each registered template directory actually exists before adding it. If the path (resolved against rootPath when relative) is not a directory, it throws this LoaderError showing both the given path and the resolved absolute path.","triggerScenarios":"Calling addPath($path) or setPaths()/prependPath() with a directory that does not exist, e.g. typo in path, relative path wrong relative to rootPath, or directory removed at runtime.","commonSituations":"Config files with wrong template directories (config/packages/twig.yaml paths); deploying to an environment where a configured directory wasn't created; relative paths assumed to be relative to CWD instead of rootPath.","solutions":["Create the missing directory or correct the path passed to addPath().","Check the second part of the message (resolved absolute path) to see where Twig looked.","Pass an absolute path if you intend the path to be independent of rootPath.","Use a container parameter/env var correctly configured in your framework's twig paths config."],"exampleFix":"// before\n$loader->addPath('/app/temlates'); // typo\n// after\n$loader->addPath('/app/templates');","handlingStrategy":"validation","validationCode":"foreach ($paths as $p) { $abs = $p[0] === '/' ? $p : $rootPath.$p; if (!is_dir($abs)) { throw new \\InvalidArgumentException(\"Twig path does not exist: $abs\"); } }","typeGuard":"function isValidTwigPath(string $rootPath, string $path): bool { $check = str_starts_with($path, '/') ? $path : $rootPath.$path; return is_dir($check); }","tryCatchPattern":"try { $loader->addPath($path); } catch (Twig\\Error\\LoaderError $e) { // create dir or correct config; message shows resolved path }","preventionTips":["Create template directories in your deploy/bootstrap script","Use absolute paths or verify rootPath resolution","Add a startup check asserting all configured twig paths are dirs"],"tags":["twig","filesystem","path-config","directory"],"backgroundTag":"directory-not-found","analyzedSha":"a414c3a491defb5a60f2fc88ef79ff37c90010cd","analyzedAt":"2026-09-13T15:10:46.849Z","contentChangedAt":"2026-09-13T15:10:46.849Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}