symfony/routing · error · InvalidArgumentException
This is not a local file
Error message
This is not a local file "%s".
What it means
YamlFileLoader::load() resolves the file via FileLocator then verifies it is a local stream (file:// or plain path). If stream_is_local() returns false — e.g. a remote stream wrapper like http:// or ftp:// — Symfony rejects it because YAML routing files must be readable as local files with resource tracking.
Solutions
- Use a local filesystem path (or bundle-relative @BundleName/Resources/config/routes.yaml) instead of a URL
- Download/copy the remote YAML to a local path at deploy time and reference that path
- Check the resolved path with stream_is_local($path) before configuring it as a routing resource
Example fix
// before
$loader->load('https://config.example.com/routes.yaml');
// after
$loader->load('/etc/app/routes.yaml'); Defensive patterns
Strategy: validation
Validate before calling
$path = $locator->locate($file); if (!stream_is_local($path)) { throw new \InvalidArgumentException("Refusing non-local routing file: $path"); } Type guard
function isLocalFile(mixed $p): bool { try { return is_string($p) && stream_is_local($p); } catch (\Throwable) { return false; } } Try / catch
try { $loader->load($file); } catch (\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'not a local file')) { /* fall back to local copy */ } throw $e; } Prevention
- Never point router resources at URLs or remote stream wrappers
- Mirror remote route configs to local files in the deploy pipeline
- Preflight stream_is_local() on dynamically computed resource paths
When it happens
Trigger: Passing a URL (http://host/routes.yaml) or a non-local stream path to the router's resource config, or a FileLocator resolving to a stream wrapper that is not local.
Common situations: Configuring framework.router.resources (or imports in routes.yaml) with a remote URL; using a custom stream wrapper; containerized setups where a path accidentally becomes an s3:// or http:// stream.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- File " " not found.
- The file " " does not contain valid YAML
- The file " " must contain a YAML array.
- Parameter " " for route " " must match " " (" " given) to…
- Parameters for route
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/86c3dc941b255874.
Report an issue: GitHub.
Appendix: source
Thrown at Loader/YamlFileLoader.php:45
class YamlFileLoader extends FileLoader
{
use ContentLoaderTrait {
parseImport as doParseImport;
parseRoute as doParseRoute;
validate as doValidate;
}
private YamlParser $yamlParser;
/**
* @throws \InvalidArgumentException When a route can't be parsed because YAML is invalid
*/
public function load(mixed $file, ?string $type = null): RouteCollection
{
$path = $this->locator->locate($file);
if (!stream_is_local($path)) {
throw new \InvalidArgumentException(\sprintf('This is not a local file "%s".', $path));
}
if (!file_exists($path)) {
throw new \InvalidArgumentException(\sprintf('File "%s" not found.', $path));
}
$this->yamlParser ??= new YamlParser();
try {
$parsedConfig = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
throw new \InvalidArgumentException(\sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);
}
$collection = new RouteCollection();
$collection->addResource(new FileResource($path));
// empty fileView on GitHub (pinned to 83fa223250)